Read list of articles from JSON blob instead of hardcoding it.
Chris Pressey
6 years ago
0 | { | |
1 | "Archived": { | |
2 | "image_url": null, | |
3 | "schema": "Tool", | |
4 | "title": "Archived" | |
5 | }, | |
6 | "Automata": { | |
7 | "image_url": "http://static.catseye.tc/images/illustrations/Perpetual_Motion_Machine.jpg", | |
8 | "schema": "Language", | |
9 | "title": "Automata" | |
10 | }, | |
11 | "Distribution Organization": { | |
12 | "image_url": null, | |
13 | "schema": null, | |
14 | "title": "Distribution Organization" | |
15 | }, | |
16 | "Electronics Projects": { | |
17 | "image_url": "http://catseye.tc/modules/electronics-projects/mildred/doc/mildred_photo.jpg", | |
18 | "schema": "Electronics Project", | |
19 | "title": "Electronics Projects" | |
20 | }, | |
21 | "Events": { | |
22 | "image_url": null, | |
23 | "schema": "Event", | |
24 | "title": "Events" | |
25 | }, | |
26 | "Formats": { | |
27 | "image_url": null, | |
28 | "schema": "Format", | |
29 | "title": "Formats" | |
30 | }, | |
31 | "Game Implementations": { | |
32 | "image_url": null, | |
33 | "schema": "Game Implementation", | |
34 | "title": "Game Implementations" | |
35 | }, | |
36 | "Games": { | |
37 | "image_url": "http://catseye.tc/modules/dungeons-of-ekileugor/images/dungeons-of-ekileugor.png", | |
38 | "schema": "Game", | |
39 | "title": "Games" | |
40 | }, | |
41 | "General Information": { | |
42 | "image_url": null, | |
43 | "schema": null, | |
44 | "title": "General Information" | |
45 | }, | |
46 | "Gewgaws": { | |
47 | "image_url": "http://static.catseye.tc/images/screenshots/Canvas_Feedback.jpg", | |
48 | "schema": "Gewgaw", | |
49 | "title": "Gewgaws" | |
50 | }, | |
51 | "HTML5 Installations": { | |
52 | "image_url": "http://static.catseye.tc/images/illustrations/Perpetual_Motion_Machine.jpg", | |
53 | "schema": "HTML5 Installation", | |
54 | "title": "HTML5 Installations" | |
55 | }, | |
56 | "Language Implementations": { | |
57 | "image_url": "http://static.catseye.tc/images/illustrations/Perpetual_Motion_Machine.jpg", | |
58 | "schema": "Language Implementation", | |
59 | "title": "Language Implementations" | |
60 | }, | |
61 | "Languages": { | |
62 | "image_url": "http://static.catseye.tc/images/illustrations/Abacus_(PSF).jpg", | |
63 | "schema": "Language", | |
64 | "title": "Languages" | |
65 | }, | |
66 | "List of Unfinished Interesting Esolangs": { | |
67 | "image_url": "http://static.catseye.tc/images/illustrations/Perpetual_Motion_Machine.jpg", | |
68 | "schema": "Unfinished Esolang", | |
69 | "title": "List of Unfinished Interesting Esolangs" | |
70 | }, | |
71 | "Movies": { | |
72 | "image_url": null, | |
73 | "schema": "Movie", | |
74 | "title": "Movies" | |
75 | }, | |
76 | "Musical Compositions": { | |
77 | "image_url": "http://static.catseye.tc/images/illustrations/Accordion_(PSF).jpg", | |
78 | "schema": "Musical Composition", | |
79 | "title": "Musical Compositions" | |
80 | }, | |
81 | "News": { | |
82 | "image_url": "http://static.catseye.tc/images/illustrations/Hatched.jpg", | |
83 | "schema": null, | |
84 | "title": "News" | |
85 | }, | |
86 | "Pictures": { | |
87 | "image_url": "http://static.catseye.tc/images/pictures/Ink%20salad%20No.%207.png", | |
88 | "schema": "Picture", | |
89 | "title": "Pictures" | |
90 | }, | |
91 | "Platforms": { | |
92 | "image_url": null, | |
93 | "schema": "Platform", | |
94 | "title": "Platforms" | |
95 | }, | |
96 | "Project Dependencies": { | |
97 | "image_url": null, | |
98 | "schema": "Project Dependency", | |
99 | "title": "Project Dependencies" | |
100 | }, | |
101 | "Retrocomputing": { | |
102 | "image_url": "http://catseye.tc/modules/dungeons-of-ekileugor/images/dungeons-of-ekileugor.png", | |
103 | "schema": null, | |
104 | "title": "Retrocomputing" | |
105 | }, | |
106 | "Texts": { | |
107 | "image_url": "http://static.catseye.tc/images/illustrations/Reader_St_Jamess_Park.jpg", | |
108 | "schema": "Text", | |
109 | "title": "Texts" | |
110 | }, | |
111 | "Tools": { | |
112 | "image_url": "http://static.catseye.tc/images/illustrations/Allen_wrench_and_screw_(PSF).jpg", | |
113 | "schema": "Tool", | |
114 | "title": "Tools" | |
115 | }, | |
116 | "Forks": { | |
117 | "image_url": "http://static.catseye.tc/images/illustrations/Allen_wrench_and_screw_(PSF).jpg", | |
118 | "schema": "Fork", | |
119 | "title": "Forks" | |
120 | } | |
121 | } |
2 | 2 | from feedmark.checkers import Schema |
3 | 3 | from feedmark.formats.markdown import feedmark_markdownize |
4 | 4 | from feedmark.loader import read_document_from, read_refdex_from |
5 | ||
6 | ||
7 | REFDEXABLE_ARTICLES = ( | |
8 | ('Distribution Organization', None,), | |
9 | ('Electronics Projects', 'Electronics Project',), | |
10 | ('Games', 'Game',), | |
11 | ('Game Implementations', 'Game Implementation',), | |
12 | ('List of Unfinished Interesting Esolangs', 'Unfinished Esolang',), | |
13 | ('Musical Compositions', 'Musical Composition',), | |
14 | ('Pictures', 'Picture',), | |
15 | ('Movies', 'Movie',), | |
16 | ('Retrocomputing', None,), | |
17 | ('Texts', 'Text',), | |
18 | ('Tools', 'Tool',), | |
19 | ('Formats', 'Format',), | |
20 | ('Platforms', 'Platform',), | |
21 | ('Archived', 'Tool',), | |
22 | ('Languages', 'Language',), | |
23 | ('Language Implementations', 'Language Implementation',), | |
24 | ('Forks', 'Fork',), | |
25 | ('Automata', 'Language',), | |
26 | ('Gewgaws', 'Gewgaw',), | |
27 | ('Events', 'Event',), | |
28 | ('General Information', None,), | |
29 | ('Project Dependencies', 'Project Dependency',), | |
30 | ) | |
31 | ||
32 | ||
33 | ARTICLES = REFDEXABLE_ARTICLES + ( | |
34 | ('HTML5 Installations', 'HTML5 Installation',), | |
35 | ('News', None,), | |
36 | ) | |
37 | 5 | |
38 | 6 | |
39 | 7 | def document_name(title): |
43 | 11 | return "article/{}.md".format(title) |
44 | 12 | |
45 | 13 | |
46 | def rewrite_documents(refdex): | |
47 | for title, schema in ARTICLES: | |
14 | def rewrite_documents(articles, refdex): | |
15 | for title, schema in articles: | |
48 | 16 | if title in ('News',): |
49 | 17 | continue |
50 | 18 | print("{}...".format(title)) |
64 | 32 | f.write(text.encode('UTF-8')) |
65 | 33 | |
66 | 34 | |
67 | def accumulate_article_refdex(refdex): | |
68 | for title, schema in REFDEXABLE_ARTICLES: | |
35 | def accumulate_article_refdex(articles, refdex): | |
36 | for title, schema in articles: | |
37 | if title in ("News", "HTML5 Installations",): | |
38 | continue | |
69 | 39 | print("{}...".format(title)) |
70 | 40 | filename = document_name(title) |
71 | 41 | document = read_document_from(filename) |
76 | 46 | } |
77 | 47 | |
78 | 48 | |
79 | def regenerate_refdex(): | |
49 | def regenerate_refdex(articles): | |
80 | 50 | INPUT_REFDEXES = [ |
81 | 51 | 'misc-refdex/games-refdex.json', |
82 | 52 | 'misc-refdex/texts-refdex.json', |
85 | 55 | 'misc-refdex/misc-refdex.json', |
86 | 56 | ] |
87 | 57 | refdex = read_refdex_from(INPUT_REFDEXES) |
88 | accumulate_article_refdex(refdex) | |
58 | accumulate_article_refdex(articles, refdex) | |
89 | 59 | with open('refdex.json', 'w') as f: |
90 | 60 | f.write(json.dumps(refdex, indent=4, sort_keys=True).encode('UTF-8')) |
91 | 61 | |
92 | 62 | |
93 | 63 | if __name__ == '__main__': |
94 | regenerate_refdex() | |
64 | with open('articles.json', 'r') as f: | |
65 | articles_map = json.loads(f.read()) | |
66 | articles = [] | |
67 | for title, properties in articles_map.items(): | |
68 | articles.append((title, properties['schema'])) | |
69 | ||
70 | regenerate_refdex(articles) | |
95 | 71 | refdex = read_refdex_from(['refdex.json'], input_refdex_filename_prefix='../') |
96 | rewrite_documents(refdex) | |
72 | rewrite_documents(articles, refdex) |