faq engine for gemini with full text search
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2 KiB

#!/usr/bin/perl
# Copyright René Wagner 2020
# licenced under BSD 3-Clause licence
# https://src.clttr.info/rwa/gmnifaq
use strict;
use DBI;
use URI::Escape;
use lib 'lib/';
use gmnifaq;
config();
# enable UTF-8 mode for everything
use utf8;
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI') {
write_response('CGI_ERROR', 'CGI execution error', undef);
}
my @body = ();
push @body, header();
push @body, tags();
push @body, footer();
write_response('SUCCESS', 'text/gemini', @body);
exit;
sub tags
{
my $dbh = DBI->connect($CONF{'dsn'}, '', '', { RaiseError => 1 }) or die $DBI::errstr;
my @result;
my @rows = $dbh->selectall_array('SELECT id, name, count(t_id) FROM tags t LEFT JOIN tags_questions tq ON tq.t_id = t.id GROUP BY t_id');
$dbh->disconnect();
if ( !scalar @rows ) {
push @result, 'No tags found!';
}
else {
foreach (@rows) {
push @result, sprintf("=> ./faqs.pl?tag=%d %s (%d entrys)", @$_[0], @$_[1], @$_[2]);
}
}
push @result, '';
return @result;
}
sub header
{
return ('# '. $CONF{'name'}, '', 'Select a tag to browse the questions associated with this tag.', '', '## Tags', '');
}