3 # InspIRCd -- Internet Relay Chat Daemon
5 # Copyright (C) 2020-2021 Sadie Powell <sadie@witchery.services>
7 # This file is part of InspIRCd. InspIRCd is free software: you can
8 # redistribute it and/or modify it under the terms of the GNU General Public
9 # License as published by the Free Software Foundation, version 2.
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 use warnings FATAL => qw(all);
25 use File::Basename qw(basename dirname);
26 use File::Spec::Functions qw(catdir catfile rel2abs);
27 use FindBin qw($RealDir);
28 use HTML::FormatText ();
29 use HTML::TreeBuilder ();
30 use Text::Markdown::Hoedown qw(HOEDOWN_HTML_SKIP_HTML markdown);
31 use Text::Sentence qw(split_sentences);
33 use lib dirname $RealDir;
37 unless (scalar @ARGV) {
38 say STDERR console_format "<|GREEN Usage:|> $0 <<|UNDERLINE DOCS-SITE|>>";
42 my %version = get_version();
43 my $docdir = rel2abs catdir $ARGV[0], 'docs', $version{MAJOR}, 'modules';
44 print_error "unable to find the module directory at $docdir!" unless -d $docdir;
46 my $root = dirname $RealDir;
47 for my $module (<$root/src/modules/extra/m_*.cpp>, <$root/src/modules/m_*.cpp>, <$root/src/modules/m_*/main.cpp>) {
48 print_error "unable to extract module name from $module!" unless $module =~ /m_(\w+)[.\/]/;
49 my $docfile = catfile $docdir, "$1.md";
50 print_error "unable to find the module documentation at $docfile!" unless -f $docfile;
52 open(my $dh, $docfile) or print_error "unable to read from $docfile: $!";
53 my $docdata = do { local $/; <$dh> };
55 print_error "unable to find the module description in $docfile!" unless $docdata =~ /\#\#\# Description\n\n(?:This module )?([^\n]+)/;
57 my $docrendered = markdown ucfirst $1, extensions => HOEDOWN_HTML_SKIP_HTML;
58 my $docplain = HTML::FormatText->new(leftmargin => 0, rightmargin => ~0)->format(HTML::TreeBuilder->new->parse($docrendered));
60 my $description = (split_sentences $docplain)[0] =~ s/"/\\"/gr;
63 open(my $mih, $module) or print_error "unable to read from $module: $!";
65 for my $line (<$mih>) {
67 if ($line =~ /(\t+return Version\(")[^"]+(",.+)/) {
68 push @lines, join '', $1, $description, $2;
75 open(my $moh, '>', $module) or print_error "unable to write to $module: $!";
76 for my $line (@lines) {