1
0
mirror of https://codeberg.org/fediverse/fep.git synced 2026-08-08 21:45:52 +00:00

Create FEP index in JSON format (#426)

Discussion https://socialhub.activitypub.rocks/t/can-we-add-a-generated-json-list-of-feps-to-the-repo/4616

Reviewed-on: https://codeberg.org/fediverse/fep/pulls/426
Reviewed-by: helge <helge@noreply.codeberg.org>
Co-authored-by: silverpill <silverpill@firemail.cc>
Co-committed-by: silverpill <silverpill@firemail.cc>
This commit is contained in:
silverpill
2024-12-16 08:40:56 +00:00
committed by helge
parent 57210be4a4
commit 18c788de7c
5 changed files with 811 additions and 10 deletions
+12 -1
View File
@@ -1,6 +1,17 @@
#!/usr/bin/env python
from tools import Readme
import json
from tools import index, Readme
with open("README.md", "w") as f1:
f1.writelines(Readme().content)
result = []
for fep in index():
data = fep.parsed_frontmatter
data["title"] = fep.title
result.append(data)
with open("index.json", "w") as index_file:
json.dump(result, index_file, indent=2)
+10 -7
View File
@@ -18,6 +18,15 @@ def build_url_link(url):
return f"[#{url_number}]({url})"
def index():
fep_files = [FepFile(fep) for fep in get_fep_ids()]
fep_files = sorted(
fep_files,
key=lambda x: (x.parsed_frontmatter["dateReceived"], x.parsed_frontmatter["slug"]),
)
return fep_files
class Readme:
@property
def content(self):
@@ -35,15 +44,9 @@ class Readme:
@property
def table(self):
fep_files = [FepFile(fep) for fep in get_fep_ids()]
fep_files = sorted(
fep_files,
key=lambda x: (x.parsed_frontmatter["dateReceived"], x.parsed_frontmatter["slug"]),
)
result = []
for fep in fep_files:
for fep in index():
link = f"[FEP-{fep.fep}: {fep.title}](./{fep.filename})"
parsed = fep.parsed_frontmatter
+8 -1
View File
@@ -1,3 +1,10 @@
def unquote(value):
if value.startswith('"') and value.endswith('"'):
return value[1:-1]
else:
return value
class FepFile:
def __init__(self, fep):
self.fep = fep
@@ -32,7 +39,7 @@ class FepFile:
@property
def parsed_frontmatter(self):
split = [x.split(":", 1) for x in self.frontmatter]
return {a: b.strip() for a, b in split}
return {a: unquote(b.strip()) for a, b in split}
@property
def title(self):
+1 -1
View File
@@ -13,7 +13,7 @@ def test_fep(fep):
assert "status" in parsed_frontmatter
assert parsed_frontmatter["status"] in ["DRAFT", "FINAL", "WITHDRAWN"]
assert parsed_frontmatter["slug"] == f'"{fep}"'
assert parsed_frontmatter["slug"] == fep
assert "authors" in parsed_frontmatter
assert "dateReceived" in parsed_frontmatter
assert "discussionsTo" in parsed_frontmatter