home » zplus/dokk.org.git
Author zPlus <zplus@peers.community> 2023-11-25 15:32:53
Committer zPlus <zplus@peers.community> 2023-11-25 15:32:53
Commit 69bf847 (patch)
Tree 96779a8
Parent(s)

Adapt manpages to new graph. The graph for manpages has changed. This commit changes all the queries for the new graph.


commits diff: d0da939..69bf847
8 files changed, 143 insertions, 102 deletionsdownload


Diffstat
-rw-r--r-- README 2
-rwxr-xr-x app.py 175
-rw-r--r-- fuseki.service 3
-rw-r--r-- pages/manpages.html 17
-rw-r--r-- pages/templates/manpages/disambiguation.tpl 12
-rw-r--r-- pages/templates/manpages/distribution.tpl 4
-rw-r--r-- pages/templates/manpages/manpage.tpl 10
-rw-r--r-- website.service 22

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+1/-1 M   README
index 0f4b030..e92f35a
old size: 1K - new size: 1K
@@ -25,7 +25,7 @@ for configuring paths or other custom settings.
25 25 python3 -m venv venv
26 26 source venv/bin/activate
27 27 pip install -r requirements.txt
28 - gunicorn --reload --worker-connections=4 --threads=4 --bind 0.0.0.0:8080 app:application
28 + gunicorn --reload --worker-connections=4 --threads=4 --bind 0.0.0.0:8080 --error-logfile=- app:application
29 29
30 30 # Crawl website for static HTML pages:
31 31

+98/-77 M   app.py
index 7904d78..cf85123
old size: 9K - new size: 9K
@@ -146,15 +146,17 @@ def manpages_distribution(distribution, version):
146 146 f'''
147 147 PREFIX mp: <dokk:manpages:>
148 148
149 - SELECT DISTINCT ?package
149 + SELECT DISTINCT ?name
150 150 WHERE {{
151 - ?id mp:source [
152 - mp:distribution_name "{distribution}" ;
153 - mp:distribution_version "{version}" ;
154 - mp:package ?package ;
155 - ] .
151 + [] a mp:Distribution ;
152 + mp:name "{distribution}" ;
153 + mp:number {version} ;
154 + mp:package ?package .
155 +
156 + ?package a mp:Package ;
157 + mp:name ?name .
156 158 }}
157 - ORDER BY ?package
159 + ORDER BY ?name
158 160 ''')
159 161
160 162 return template('templates/manpages/distribution.tpl', data=data, distribution=distribution, version=version)
@@ -169,102 +171,121 @@ def manpages_package(distribution, version, package):
169 171 f'''
170 172 PREFIX mp: <dokk:manpages:>
171 173
172 - SELECT ?id ?filename
174 + SELECT (?page as ?id) ?filename
173 175 WHERE {{
174 - ?id mp:source [
175 - mp:package "{package}" ;
176 - mp:distribution_version "{version}" ;
177 - mp:distribution_name "{distribution}" ;
178 - mp:filename ?filename ;
179 - ] .
176 + [] a mp:Distribution ;
177 + mp:name "{distribution}" ;
178 + mp:number {version} ;
179 + mp:package ?package .
180 +
181 + ?package a mp:Package ;
182 + mp:name "{package}" ;
183 + mp:page ?page .
184 +
185 + ?page a mp:Page ;
186 + mp:filename ?filename
180 187 }}
181 188 ORDER BY ?filename
182 189 ''')
183 190
184 191 return template('templates/manpages/package.tpl', data=data, distribution=distribution, version=version, package=package)
185 192
186 - @bottle.get('/manpages/<distribution>/<version>/<package>/<name>.<section>.<lang>', name='manpages_page')
187 - def manpages_page(distribution, version, package, name, section, lang):
193 + @bottle.get('/manpages/<name>.<section>', name='manpages_disambiguation')
194 + def manpages_disambiguation(name, section):
188 195 """
189 - Display a single manpage.
196 + Show a list of manpages that match <name> and <section>
190 197 """
191 198
192 - page_id = f'<dokk:manpages:{distribution}/{version}/{package}/{name}.{section}.{lang}>'
193 -
194 - # These characters where url-encoded when creating the RDF data because they
195 - # make invalid URIs. This means for example that in the graph the URIs will be
196 - # encoded with %23 instead of #
197 - page_id = page_id.replace(' ', '_') \
198 - .replace('[', '%5B') \
199 - .replace(']', '%5D') \
200 - .replace('#', '%23')
201 -
202 199 data = query(
203 200 f'''
204 201 PREFIX mp: <dokk:manpages:>
205 202
206 - DESCRIBE {page_id}
207 - ''',
208 - {
209 - '@context': {
210 - 'mp': 'dokk:manpages:',
211 - },
212 - 'mp:source': {},
213 - })
214 -
215 - # Replace references to other manpages with links.
216 - # Manpages have a section "See also" at the bottom where they suggest other pages.
217 - # For example:
218 - # SEE ALSO
219 - # cdk(3), cdk_screen(3), cdk_display(3), cdk_binding(3), cdk_util(3)
220 - # We convert these strings to links to other pages.
221 - # Example: ls(1) -> <a href="...">ls(1)</a>
222 - # regex explanation:
223 - # - some manpages use a bold or italic name, so we match an optional <b>
224 - # <i> tag
225 - # - match valid characters for a manpage, assign name <page>
226 - # - match optional closing </em> or </strong> tags
227 - # - match '('
228 - # - match number, assign name <section>
229 - # - match ')'
230 - html = data['@graph'][0]['mp:html']
231 - html = re.sub (
232 - '(?:<b>|<i>)?(?P<page>[\w_.:-]+)(?:</b>|</i>)?\((?P<section>[0-9]\w*)\)',
233 - lambda match:
234 - f'''<a href="{application.get_url('manpages_disambiguation',
235 - name=match.group('page'), section=match.group('section')).lower()}"
236 - >{match.group('page')}({match.group('section')})</a>''',
237 - html)
238 -
239 - data['@graph'][0]['mp:html'] = html
203 + SELECT *
204 + WHERE {{
205 + ?page a mp:Page ;
206 + mp:filename ?filename ;
207 + mp:name_lowercase "{name}" ;
208 + mp:section_lowercase "{section}" .
209 +
210 + ?package a mp:Package ;
211 + mp:name ?package_name ;
212 + mp:page ?page .
213 +
214 + ?distro a mp:Distribution ;
215 + mp:name ?distro_name ;
216 + mp:number ?distro_number ;
217 + mp:package ?package .
218 + }}
219 + ORDER BY ?distro_name ?distro_number ?package_name
220 + ''')['results']['bindings']
240 221
241 - return template('templates/manpages/manpage.tpl', data=data['@graph'][0], distribution=distribution,
242 - version=version, package=package, name=name, section=section, lang=lang)
222 + return template('templates/manpages/disambiguation.tpl', name=name, section=section, data=data)
243 223
244 - @bottle.get('/manpages/<name>.<section>', name='manpages_disambiguation')
245 - def manpages_disambiguation(name, section):
224 + @bottle.get('/manpages/<distro_name>/<distro_number>/<package>/<page>', name='manpages_page')
225 + def manpages_page(distro_name, distro_number, package, page):
246 226 """
247 - Show a list of manpages that match <name> and <section>
227 + Display a single manpage.
248 228 """
249 229
250 230 data = query(
251 231 f'''
252 232 PREFIX mp: <dokk:manpages:>
253 233
254 - DESCRIBE ?page
234 + SELECT *
255 235 WHERE {{
256 - ?page mp:name_lowercase "{name}" ;
257 - mp:section_lowercase "{section}" .
236 + ?page a mp:Page ;
237 + mp:filename "{page}" ;
238 + mp:name ?page_name ;
239 + mp:section ?page_section ;
240 + mp:html ?page_html .
241 +
242 + ?package a mp:Package ;
243 + mp:name "{package}" ;
244 + mp:page ?page .
245 +
246 + ?distro a mp:Distribution ;
247 + mp:name "{distro_name}" ;
248 + mp:number {distro_number} ;
249 + mp:package ?package .
258 250 }}
259 - ''',
260 - {
261 - '@context': {
262 - 'mp': 'dokk:manpages:',
263 - },
264 - 'mp:source': {},
265 - })
251 + ''')['results']['bindings'][0]
252 +
253 + """
254 + Replace references to other manpages with links.
255 + Manpages have a section "See also" at the bottom where they suggest other pages.
256 + For example:
257 + SEE ALSO
258 + cdk(3), cdk_screen(3), cdk_display(3), cdk_binding(3), cdk_util(3)
259 + We convert these strings to links to other pages.
260 + Example: ls(1) -> <a href="...">ls(1)</a>
261 + regex explanation:
262 + - some manpages use a bold or italic name, so we match an optional <b>
263 + <i> tag
264 + - match valid characters for a manpage, assign name <page>
265 + - match optional closing </em> or </strong> tags
266 + - match '('
267 + - match number, assign name <section>
268 + - match ')'
269 + """
270 +
271 + html = data['page_html']['value']
272 + html = re.sub (
273 + '(?:<b>|<i>)?(?P<page>[\w_.:-]+)(?:</b>|</i>)?\((?P<section>[0-9]\w*)\)',
274 + lambda match:
275 + f'''<a href="{application.get_url('manpages_disambiguation',
276 + name=match.group('page'), section=match.group('section')).lower()}"
277 + >{match.group('page')}({match.group('section')})</a>''',
278 + html)
266 279
267 - return template('templates/manpages/disambiguation.tpl', name=name, section=section, data=data)
280 + return template('templates/manpages/manpage.tpl',
281 + distro = {'name': distro_name, 'number': distro_number},
282 + package = package,
283 + page = {
284 + 'filename': page,
285 + 'name': data['page_name']['value'],
286 + 'section': data['page_section']['value'],
287 + 'html': html,
288 + })
268 289
269 290 @bottle.get('/mimi_and_eunice/<number>', name='mimi_and_eunice_strip')
270 291 def mimi_and_eunice_strip(number):

+1/-2 M   fuseki.service
index ee76775..792d751
old size: 1K - new size: 1K
@@ -1,5 +1,4 @@
1 - # This is an example service file for systemd. If using the Fuseki server, this
2 - # service can be configured to automatically start the server.
1 + # systemd service file for starting the Fuseki server
3 2 #
4 3 # How to use this file:
5 4 # - copy this file to /etc/systemd/system

+8/-9 M   pages/manpages.html
index 72c9b2a..7bb4714
old size: 924B - new size: 831B
@@ -3,14 +3,13 @@
3 3 {% set data = query("""
4 4 PREFIX mp: <dokk:manpages:>
5 5
6 - SELECT DISTINCT ?distribution ?version
6 + SELECT ?name ?number
7 7 WHERE {
8 - [] mp:source [
9 - mp:distribution_version ?version ;
10 - mp:distribution_name ?distribution ;
11 - ] .
8 + [] a mp:Distribution ;
9 + mp:name ?name ;
10 + mp:number ?number
12 11 }
13 - ORDER BY ?distribution ?version
12 + ORDER BY ?name ?number
14 13 """)
15 14 %}
16 15
@@ -31,9 +30,9 @@
31 30
32 31 {% for result in data["results"]["bindings"] %}
33 32 <div>
34 - <a href="{{ url('manpages_distribution', distribution=result['distribution']['value'], version=result['version']['value']) }}">
35 - {{ result["distribution"]["value"] }}
36 - {{ result["version"]["value"] }}
33 + <a href="{{ url('manpages_distribution', distribution=result['name']['value'], version=result['number']['value']) }}">
34 + {{ result["name"]["value"] }}
35 + {{ result["number"]["value"] }}
37 36 </a>
38 37 </div>
39 38 {% endfor %}

+6/-6 M   pages/templates/manpages/disambiguation.tpl
index 5c046ff..7b4bd3d
old size: 929B - new size: 906B
@@ -17,18 +17,18 @@
17 17
18 18 <p>
19 19 <table>
20 - {% for page in data["@graph"] %}
20 + {% for result in data %}
21 21 <tr>
22 22 <td>
23 - <a href="/manpages/{{ page['@id'][3:] }}">
24 - {{ page['mp:source']['mp:filename'] }}
23 + <a href="/manpages/{{ result['page']['value'][14:] }}">
24 + {{ result['filename']['value'] }}
25 25 </a>
26 26 </td>
27 27 <td>
28 - {{ page['mp:source']['mp:distribution_name'] }}
29 - {{ page['mp:source']['mp:distribution_version'] }}
28 + {{ result['distro_name']['value'] }}
29 + {{ result['distro_number']['value'] }}
30 30 /
31 - {{ page['mp:source']['mp:package'] }}
31 + {{ result['package_name']['value'] }}
32 32 </td>
33 33 </tr>
34 34 {% endfor %}

+2/-2 M   pages/templates/manpages/distribution.tpl
index a5c36df..f403bec
old size: 624B - new size: 627B
@@ -16,9 +16,9 @@
16 16 Packages:
17 17 </p>
18 18
19 - {% for page in data['results']['bindings'] %}
19 + {% for package in data['results']['bindings'] %}
20 20 <div>
21 - <a href="{{ url('manpages_package', distribution=distribution, version=version, package=page['package']['value']) }}">{{ page['package']['value'] }}</a>
21 + <a href="{{ url('manpages_package', distribution=distribution, version=version, package=package['name']['value']) }}">{{ package['name']['value'] }}</a>
22 22 </div>
23 23 {% endfor %}
24 24

+5/-5 M   pages/templates/manpages/manpage.tpl
index cbbff47..a0e850d
old size: 754B - new size: 762B
@@ -1,6 +1,6 @@
1 1 {% extends "templates/base.tpl" %}
2 2
3 - {% block title %}{{ data['mp:name'] }}({{ data['mp:section'] }}){% endblock %}
3 + {% block title %}{{ page["name"] }}({{ page["section"] }}){% endblock %}
4 4 {% block stylesheets %}
5 5 <link href="/static/css/mandoc.css" rel="stylesheet">
6 6 {% endblock %}
@@ -12,12 +12,12 @@
12 12 <div class="path">
13 13 <a href="/">DOKK</a> /
14 14 <a href="/manpages">manpages</a> /
15 - <a href="{{ url('manpages_distribution', distribution=distribution, version=version) }}">{{ distribution }} {{ version }}</a> /
16 - <a href="{{ url('manpages_package', distribution=distribution, version=version, package=package) }}">{{ package }}</a> /
17 - {{ data["mp:source"]["mp:filename"] }}
15 + <a href="{{ url('manpages_distribution', distribution=distro["name"], version=distro["number"]) }}">{{ distro["name"] }} {{ distro["number"] }}</a> /
16 + <a href="{{ url('manpages_package', distribution=distro["name"], version=distro["number"], package=package) }}">{{ package }}</a> /
17 + {{ page["filename"] }}
18 18 </div>
19 19
20 - <div class="manpage">{{ data["mp:html"]|safe }}</div>
20 + <div class="manpage">{{ page["html"]|safe }}</div>
21 21
22 22 </div>
23 23

+22/-0 A   website.service
index 0000000..0586f33
old size: 0B - new size: 513B
new file mode: -rw-r--r--
@@ -0,0 +1,22 @@
1 + # systemd service file for starting the web app
2 + #
3 + # How to use this file:
4 + # - copy this file to /etc/systemd/system
5 + # - edit the variables below accordingly
6 + # - systemctl enable website.service
7 + # - systemctl start website.service
8 +
9 + [Unit]
10 + Description=DOKK website app
11 + After=network.target
12 +
13 + [Service]
14 + ExecStart=/home/fuseki/dokk.org/venv/bin/gunicorn --bind localhost:8080 app:application
15 +
16 + User=fuseki
17 + Group=fuseki
18 + WorkingDirectory=/home/fuseki/dokk.org
19 + Restart=always
20 +
21 + [Install]
22 + WantedBy=multi-user.target