blog

git clone https://git.ce9e.org/blog.git

commit
b19647ead29ec3d12b90159068a351d5e5d27d6b
parent
d687b9ef93982008c2c5e366eef6c4be3c3fcecb
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-09-05 11:52
generate projects page from github

Diffstat

M Makefile 7 ++++++-
M _templates/base.html 1 +
A projects.py 34 ++++++++++++++++++++++++++++++++++

3 files changed, 41 insertions, 1 deletions


diff --git a/Makefile b/Makefile

@@ -7,7 +7,7 @@ IMG := $(shell find _content -regex '.*\.\(png\|gif\|jpg\)$$' | sed 's/^_content
    7     7 PANDOC_ARGS = -f markdown-smart --wrap=none --lua-filter filters/*.lua
    8     8 
    9     9 .PHONY: all
   10    -1 all: $(IMG) build/index.html $(PAGES) $(PAGES_MD) build/feed.xml build/feed-archive.xml build/feed.json build/feed-archive.json $(STATIC) build/static/style.css
   -1    10 all: $(IMG) build/index.html build/projects/index.html $(PAGES) $(PAGES_MD) build/feed.xml build/feed-archive.xml build/feed.json build/feed-archive.json $(STATIC) build/static/style.css
   11    11 
   12    12 .PHONY: push
   13    13 push: all
@@ -25,6 +25,11 @@ build/index.md: _content/posts/*/index.md posts.sh
   25    25 	@mkdir -p $$(dirname $@)
   26    26 	./posts.sh > $@
   27    27 
   -1    28 .PHONY: build/projects/index.md
   -1    29 build/projects/index.md: projects.py
   -1    30 	@mkdir -p $$(dirname $@)
   -1    31 	python3 projects.py > $@
   -1    32 
   28    33 _content/%.html: _content/%.md filters/*.lua
   29    34 	pandoc $(PANDOC_ARGS) $< -o $@
   30    35 	@sed -i 's/<tr class="header">/<tr>/g' $@

diff --git a/_templates/base.html b/_templates/base.html

@@ -22,6 +22,7 @@
   22    22 		<nav class="header__nav">
   23    23 			<ul vocab="http://xmlns.com/foaf/0.1/" typeof="person">
   24    24 				<li><a href="https://blog.ce9e.org/" property="homepage">blog</a></li>
   -1    25 				<li><a href="/projects/">projects</a></li>
   25    26 				<li><a href="https://github.com/xi" property="account">github</a></li>
   26    27 				<li><a href="mailto:tobias.bengfort@posteo.de" property="email name">mail</a></li>
   27    28 			</ul>

diff --git a/projects.py b/projects.py

@@ -0,0 +1,34 @@
   -1     1 import itertools
   -1     2 import requests
   -1     3 
   -1     4 
   -1     5 def iter_repos(username):
   -1     6     for page in itertools.count(1):
   -1     7         response = requests.get(
   -1     8             f'https://api.github.com/users/{username}/repos',
   -1     9             {
   -1    10                 'page': page,
   -1    11                 'per_page': 100,
   -1    12                 'sort': 'created',
   -1    13             },
   -1    14         )
   -1    15         response.raise_for_status()
   -1    16         repos = response.json()
   -1    17         for repo in repos:
   -1    18             if not repo['fork'] and not repo['archived']:
   -1    19                 yield repo
   -1    20         if len(repos) < 100:
   -1    21             break
   -1    22 
   -1    23 
   -1    24 if __name__ == '__main__':
   -1    25     print('---\ntitle: projects\n---')
   -1    26 
   -1    27     prev_year = None
   -1    28     for repo in iter_repos('xi'):
   -1    29         year = repo['created_at'][:4]
   -1    30         if year != prev_year:
   -1    31             print(f'\n## {year}\n')
   -1    32         prev_year = year
   -1    33 
   -1    34         print('- [{name}]({html_url}) - {description}'.format(**repo))