diff --git a/README.md b/README.md

index d56288ac5f5e3b0666701ae469af8a26d70a3a91..01c987e596a8b37c5f8adee405339658948bbdeb 100644

--- a/README.md

+++ b/README.md

@@ -3,7 +3,9 @@

*orrg* is a cgi script for [gemini](gemini://gemini.circumlunar.space) servers.

It delivers an easy way to consume atom or rss feeds shipped over http(s) within gemini.

-Visit the [demo](gemini://gmndemo.clttr.info/orrg.pl?https:%2F%2Fgit.sr.ht%2F~rwa%2Forrg%2Flog%2Frss.xml) ([through http proxy](https://portal.mozz.us/gemini/gmndemo.clttr.info/orrg.pl%3Fhttps:%252F%252Fgit.sr.ht%252F~rwa%252Forrg%252Flog%252Frss.xml)) that shows the commit log of this repo.

+Lists of popular and recently visited feeds help you discover new things.

+

+Visit the [demo](gemini://gmndemo.clttr.info/orrg/orrg.pl?https:%2F%2Fgit.sr.ht%2F~rwa%2Forrg%2Flog%2Frss.xml) ([through http proxy](https://portal.mozz.us/gemini/gmndemo.clttr.info/orrg.pl%3Fhttps:%252F%252Fgit.sr.ht%252F~rwa%252Forrg%252Flog%252Frss.xml)) that shows the commit log of this repo.

The demo might break regularly as i use it for integration testing during development.

## features

@@ -12,12 +14,15 @@ - load an atom/rss feed from http(s) given by user input

- render feed (channel info & entrys) as a gemini site

- include links to originating site and every article

- strip html tags from item description

+- lists of popular and recently visited feeds

Fetching feeds from gemini is currently not supported -> https://todo.sr.ht/~rwa/gmni-perl/4

## non-features

-*orrg* is more of a PoC and will never be a full-fletched feed aggregator with archiving and searching capabilities.

+*orrg* will never be a full-fletched feed aggregator with archiving and searching capabilities.

+

+Given this restrictions is not suitable for highly traffic feeds which are updated very often. But it should work quite well

# installation

diff --git a/index.pl b/index.pl

new file mode 100755

index 0000000000000000000000000000000000000000..14fe354925780511523d735cbd8e16051053ea00

--- /dev/null

+++ b/index.pl

@@ -0,0 +1,27 @@

+#!/usr/bin/perl

+# Copyright René Wagner 2020

+# licenced under BSD 3-Clause licence

+# https://git.sr.ht/~rwa/orrg

+

+use strict;

+use DBI;

+use lib 'lib/';

+use orrg;

+

+# 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);

+}

+

+write_response('SUCCESS', 'text/gemini', body());

+

+exit;

+

+sub body

+{

+ return ('# Welcome to orrg', '', 'orrg is your online rss/atom feed reader for gemini.', '', '=> orrg.pl view a feed', '', '## explore', '', '=> recent.pl top 10 recent feeds', '=> popular.pl top 10 popular feeds', '', '', '=> https://git.sr.ht/~rwa/orrg powered by orrg');

+}

diff --git a/lib/orrg.pm b/lib/orrg.pm

new file mode 100755

index 0000000000000000000000000000000000000000..e4ca572f0b36c8b0eb3725c8f1f7f11dc0e3de4a

--- /dev/null

+++ b/lib/orrg.pm

@@ -0,0 +1,53 @@

+#!/usr/bin/perl

+# Copyright René Wagner 2020

+# licenced under BSD 3-Clause licence

+# https://git.sr.ht/~rwa/orrg

+

+package orrg;

+use strict;

+use Exporter;

+our @ISA = qw(Exporter);

+our @EXPORT = qw(write_response %RC); # automatically exported subs

+

+# enable UTF-8 mode for everything

+use utf8;

+binmode STDOUT, ':utf8';

+binmode STDERR, ':utf8';

+

+# define return codes

+our %RC = (

+ 'INPUT', 10,

+ 'SENSITIVE_INPUT', 11,

+ 'SUCCESS', 20,

+ 'TEMPORARY_REDIRECT', 30,

+ 'PERMANENT_REDIRECT', 31,

+ 'TEMPORARY_FAILURE', 40,

+ 'SERVER_UNAVAILABLE', 41,

+ 'CGI_ERROR', 42,

+ 'PROXY_ERROR', 43,

+ 'SLOW_DOWN', 44,

+ 'PERMANENT_FAILURE', 50,

+ 'NOT_FOUND', 51,

+ 'GONE', 52,

+ 'PROXY_REQUEST_REFUSE', 53,

+ 'BAD_REQUEST', 59,

+ 'CLIENT_CERT_REQUIRED', 60,

+ 'CERT_NOT_AUTHORISED', 61,

+ 'CERT_NOT_VALID', 62

+);

+

+sub write_response

+{

+ my ($returncode, $meta, @content) = @_;

+

+ if (!defined($RC{$returncode})) { die "Unknown response code!"; }

+

+ printf("%d %s\r\n", $RC{$returncode}, ($meta eq '') ? $returncode : $meta);

+ foreach (@content) {

+ print("$_\r\n");

+ }

+

+ exit;

+}

+

+1;

diff --git a/orrg.pl b/orrg.pl

index 35458b2a68e7db614afe7cda48d6673840e23b57..5cf31e2c5c5aaa1270cbeac8e19af7f7a44c0544 100755

--- a/orrg.pl

+++ b/orrg.pl

@@ -11,33 +11,13 @@ use HTML::Strip;

use DateTime;

use DateTime::Format::ISO8601;

use POSIX qw(strftime);

+use lib 'lib/';

+use orrg;

# enable UTF-8 mode for everything

use utf8;

binmode STDOUT, ':utf8';

binmode STDERR, ':utf8';

-

-# define return codes

-our %RC = (

- 'INPUT', 10,

- 'SENSITIVE_INPUT', 11,

- 'SUCCESS', 20,

- 'TEMPORARY_REDIRECT', 30,

- 'PERMANENT_REDIRECT', 31,

- 'TEMPORARY_FAILURE', 40,

- 'SERVER_UNAVAILABLE', 41,

- 'CGI_ERROR', 42,

- 'PROXY_ERROR', 43,

- 'SLOW_DOWN', 44,

- 'PERMANENT_FAILURE', 50,

- 'NOT_FOUND', 51,

- 'GONE', 52,

- 'PROXY_REQUEST_REFUSE', 53,

- 'BAD_REQUEST', 59,

- 'CLIENT_CERT_REQUIRED', 60,

- 'CERT_NOT_AUTHORISED', 61,

- 'CERT_NOT_VALID', 62

- );

if (!defined($ENV{'SERVER_PROTOCOL'}) || $ENV{'SERVER_PROTOCOL'} ne 'GEMINI')

{

@@ -90,19 +70,6 @@ }

$it->link eq '' or push @body, ('=> '.$it->link.' open entry in browser', '');

}

+ push @body, ('', '', '=> index.pl [home]');

return @body;

}

-

-sub write_response

-{

- my ($returncode, $meta, @content) = @_;

-

- if (!defined($RC{$returncode})) { die "Unknown response code!"; }

-

- printf("%d %s\r\n", $RC{$returncode}, ($meta eq '') ? $returncode : $meta);

- foreach (@content) {

- print("$_\r\n");

- }

-

- exit;

-}