From e89559e5371762510f144aac75113bf709a0036c Mon Sep 17 00:00:00 2001 From: zPlus <zplus@peers.community> Date: Fri, 27 Dec 2024 13:28:13 +0100 Subject: [PATCH] Add "Comics" section. - Add XKCD - Move Mimi&Eunice to Comics section --- app.py | 86 ++++++++++++++++++- templates/comics/index.html | 21 +++++ .../{ => comics}/mimi_and_eunice/index.html | 0 .../{ => comics}/mimi_and_eunice/strip.html | 2 +- templates/comics/xkcd/index.html | 16 ++++ templates/comics/xkcd/strip.html | 22 +++++ templates/index.html | 2 +- 7 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 templates/comics/index.html rename templates/{ => comics}/mimi_and_eunice/index.html (100%) rename templates/{ => comics}/mimi_and_eunice/strip.html (98%) create mode 100644 templates/comics/xkcd/index.html create mode 100644 templates/comics/xkcd/strip.html diff --git a/app.py b/app.py index ad971da..9ad73bb 100755 --- a/app.py +++ b/app.py @@ -451,7 +451,28 @@ def manpages_page(distro_name, distro_number, package, page): 'html': html, }) -@bottle.get('/mimi_and_eunice', name='mimi_and_eunice') +@bottle.get('/comics', name='comics') +def comics(): + """ + Comics index. + """ + + data = query(""" + PREFIX comics: <dokk:vocab:comicstrip:> + + SELECT DISTINCT ?id ?title + WHERE { + ?id a comics:ComicStrip ; + comics:title ?title + } + ORDER BY ?id + """) + + pages = data['results']['bindings'] + + return template('comics/index.html', pages=pages) + +@bottle.get('/comics/mimi_and_eunice', name='mimi_and_eunice') def mimi_and_eunice(): """ Mimi&Eunice index. @@ -469,9 +490,9 @@ def mimi_and_eunice(): ORDER BY ?number """) - return template('mimi_and_eunice/index.html', data=data) + return template('comics/mimi_and_eunice/index.html', data=data) -@bottle.get('/mimi_and_eunice/<number>', name='mimi_and_eunice_strip') +@bottle.get('/comics/mimi_and_eunice/<number>', name='mimi_and_eunice_strip') def mimi_and_eunice_strip(number): """ """ @@ -505,7 +526,64 @@ def mimi_and_eunice_strip(number): 'blob:at': {} }) - return template('mimi_and_eunice/strip.html', data=data['@graph'][0]) + return template('comics/mimi_and_eunice/strip.html', data=data['@graph'][0]) + +@bottle.get('/comics/xkcd', name='xkcd') +def xkcd(): + """ + XKCD index. + """ + + data = query(f""" + PREFIX comics: <dokk:vocab:comicstrip:> + + SELECT ?id ?number ?title + WHERE {{ + ?id comics:series <dokk:xkcd> ; + comics:number ?number ; + comics:title ?title + }} + ORDER BY ?number + """) + + data = data['results']['bindings'] + + return template('comics/xkcd/index.html', data=data) + +@bottle.get('/comics/xkcd/<number>', name='xkcd_strip') +def xkcd_strip(number): + """ + """ + + iri = '<dokk:xkcd_comic_' + number + '>' + + data = query(f''' + prefix blob: <dokk:vocab:blob:> + prefix license: <dokk:vocab:license:> + prefix comics: <dokk:vocab:comicstrip:> + + DESCRIBE {iri} ?license ?blob + WHERE + {{ + {iri} a comics:ComicStripPanel ; + comics:license ?license; + blob:at ?blob + }} + ''', + { + '@context': { + 'blob': 'dokk:vocab:blob:', + 'license': 'dokk:vocab:license:', + 'comics': 'dokk:vocab:comicstrip:', + 'comics:tag': { '@container': '@set' }, + 'comics:transcript': { '@container': '@set' } + }, + '@type': 'comics:ComicStripPanel', + 'comics:license': {}, + 'blob:at': {} + }) + + return template('comics/xkcd/strip.html', data=data['@graph'][0]) @bottle.get('/articles', name='articles') def articles(): diff --git a/templates/comics/index.html b/templates/comics/index.html new file mode 100644 index 0000000..307b952 --- /dev/null +++ b/templates/comics/index.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} + +{% block title %}Comics{% endblock %} + +{% block body %} + +<div class="comics"> + + <div class="path"> + <a href="{{ url('homepage') }}">DOKK</a> / + comics + </div> + + {% for page in pages %} + <p> + <a href="/comics/{{ page['id']['value'][5:] }}">{{ page['title']['value'] }}</a> + </p> + {% endfor %} +</div> + +{% endblock %} diff --git a/templates/mimi_and_eunice/index.html b/templates/comics/mimi_and_eunice/index.html similarity index 100% rename from templates/mimi_and_eunice/index.html rename to templates/comics/mimi_and_eunice/index.html diff --git a/templates/mimi_and_eunice/strip.html b/templates/comics/mimi_and_eunice/strip.html similarity index 98% rename from templates/mimi_and_eunice/strip.html rename to templates/comics/mimi_and_eunice/strip.html index c162f56..184f505 100644 --- a/templates/mimi_and_eunice/strip.html +++ b/templates/comics/mimi_and_eunice/strip.html @@ -11,7 +11,7 @@ Published: {{ data['comics:published'] }} </p> <p> - Liense: + License: <a href="{{ url('license', id=data['comics:license']['license:id']) }}">{{ data['comics:license']['license:id'] }}</a> </p> <p> diff --git a/templates/comics/xkcd/index.html b/templates/comics/xkcd/index.html new file mode 100644 index 0000000..7a83aa7 --- /dev/null +++ b/templates/comics/xkcd/index.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %}XKCD{% endblock %} + +{% block body %} + +<div class=""> +{% for comic_strip in data %} + <p> + {{ comic_strip['number']['value'] }} - + <a href="{{ url('xkcd_strip', number=comic_strip['number']['value']) }}">{{ comic_strip['title']['value'] }}</a> + </p> +{% endfor %} +</div> + +{% endblock %} diff --git a/templates/comics/xkcd/strip.html b/templates/comics/xkcd/strip.html new file mode 100644 index 0000000..4ca77b5 --- /dev/null +++ b/templates/comics/xkcd/strip.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + +{% block title %}XKCD {{ data['comics:number']['@value'] }}: {{ data['comics:title'] }}{% endblock %} + +{% block body %} + +<div class="xkcd_strip"> + <h1>{{ data['comics:title'] }}</h1> + + <p> + Published: {{ data['comics:published'] }} + </p> + <p> + License: + <a href="{{ url('license', id=data['comics:license']['license:id']) }}">{{ data['comics:license']['license:id'] }}</a> + </p> + + <img src="https://blob.dokk.org/{{ data['blob:at']['@id'][8:] }}" title="{{ data['comics:xkcd_alt'] }}" /> + +</div> + +{% endblock %} diff --git a/templates/index.html b/templates/index.html index 83bc128..f0bc8d6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,7 +12,7 @@ <p>- <a href="/library">Library</a></p> <p>- <a href="/license">Licenses</a></p> <p>- <a href="/manpages">Man pages</a></p> - <p>- <a href="/mimi_and_eunice">Mimi & Eunice comic strips</a></p> + <p>- <a href="/comics">Comics</a></p> <br /><br /><br /><br />