3 # InspIRCd -- Internet Relay Chat Daemon
5 # Copyright (C) 2020 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 unless (-f 'configure') {
24 print "Error: $0 must be run from the main source directory!\n";
31 use warnings FATAL => qw(all);
33 use File::Basename qw(basename dirname);
34 use File::Spec::Functions qw(catdir catfile rel2abs);
35 use FindBin qw($RealDir);
36 use HTML::FormatText ();
37 use HTML::TreeBuilder ();
38 use Text::Markdown::Hoedown qw(HOEDOWN_HTML_SKIP_HTML markdown);
39 use Text::Sentence qw(split_sentences);
41 use lib dirname $RealDir;
45 if (scalar @ARGV < 1) {
46 print_format "<|GREEN Usage:|> $0 <<|UNDERLINE DOCS-SITE|>>\n", *STDERR;
50 my %version = get_version();
51 my $docdir = rel2abs catdir $ARGV[0], 'docs', $version{MAJOR}, 'modules';
52 print_error "unable to find the module directory at $docdir!" unless -d $docdir;
54 for my $module (<src/modules/extra/m_*.cpp>, <src/modules/m_*.cpp>, <src/modules/m_*/main.cpp>) {
55 print_error "unable to extract module name from $module!" unless $module =~ /m_(\w+)[.\/]/;
56 my $docfile = catfile $docdir, "$1.md";
57 print_error "unable to find the module documentation at $docfile!" unless -f $docfile;
59 open(my $dh, $docfile) or print_error "unable to read from $docfile: $!";
60 my $docdata = do { local $/; <$dh> };
62 print_error "unable to find the module description in $docfile!" unless $docdata =~ /\#\#\# Description\n\n(?:This module )?([^\n]+)/;
64 my $docrendered = markdown ucfirst $1, extensions => HOEDOWN_HTML_SKIP_HTML;
65 my $docplain = HTML::FormatText->new(leftmargin => 0, rightmargin => ~0)->format(HTML::TreeBuilder->new->parse($docrendered));
67 my $description = (split_sentences $docplain)[0] =~ s/"/\\"/gr;
70 open(my $mih, $module) or print_error "unable to read from $module: $!";
72 for my $line (<$mih>) {
74 if ($line =~ /(\t+return Version\(")[^"]+(",.+)/) {
75 push @lines, join '', $1, $description, $2;
82 open(my $moh, '>', $module) or print_error "unable to write to $module: $!";
83 for my $line (@lines) {