Skip to content

Commit a300e62

Browse files
authored
Turn blog_posts.json slugs into ReScript data (#338)
This removes some dangerous file reading while letting us do some better computations on them. Later, we could also rearrange the archived posts detection more straightforwardly.
1 parent f459397 commit a300e62

File tree

7 files changed

+382
-181
lines changed

7 files changed

+382
-181
lines changed

data/blog_posts.json

Lines changed: 0 additions & 62 deletions
This file was deleted.

pages/blogpost-guide.mdx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@ touch _blogposts/2020-01-30-my-new-blog-post.mdx
2828

2929
### Map the file to a URL
3030

31-
Open the `data/blog_posts.json` file and add a new mapping like this:
31+
Open the `src/BlogData.res` file and add a new mapping like this:
3232

33-
```
34-
{
35-
"my-new-blog-post": "2020-01-30-my-new-blog-post.mdx",
36-
}
33+
```res
34+
("my-new-blog-post", "2020-01-30-my-new-blog-post.mdx")
3735
```
3836

39-
The key describes the final slug (e.g. `/blog/my-new-blog-post`), while the value defines the relative filepath within the `_blogposts` directory.
37+
The first item describes the final slug (e.g. `/blog/my-new-blog-post`), while the second defines the relative filepath within the `_blogposts` directory, without the extension.
4038

41-
Save your changes within `data/blog_posts.json` and refresh your browser within [/blog](/blog).
42-
You should now see a warning for some malformed frontmatter data. Let's fix this!
39+
Save your changes within and refresh your browser within [/blog](/blog). You should now see a warning for some malformed frontmatter data. Let's fix this!
4340

4441
## Add Frontmatter Data
4542

scripts/test-hrefs.mjs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,18 @@ import path from "path";
1414
import fs from "fs";
1515
import urlModule from "url";
1616
import { URL } from 'url';
17+
import {data as blogIndex} from '../src/BlogData.mjs'
1718

1819
const __dirname = new URL('.', import.meta.url).pathname;
1920

20-
const blog_index = JSON.parse(fs.readFileSync(path.join(__dirname, "../data/blog_posts.json"), "utf8"))
21-
22-
//const blog_index = require("../data/blog_posts.json");
23-
24-
25-
26-
// Our blogpost urls are mapped via `data/blog_posts.json`
27-
// the blog_posts file has following structure: { [slug]: [filepath relative to _blogposts] }
2821
const mapBlogFilePath = path => {
29-
const match = path.match(/\.\/_blogposts\/(.*\.mdx)/);
22+
const match = path.match(/\.\/_blogposts\/(.*)\.mdx/);
3023

3124
if (match) {
3225
let relPath = match[1];
33-
let slug = Object.keys(blog_index).find(key => blog_index[key] === relPath);
34-
if (slug != null) {
35-
return `./pages/blog/${slug}`;
26+
let slugAndFullslug = blogIndex.find(({fullslug}) => fullslug === relPath);
27+
if (slugAndFullslug != null) {
28+
return `./pages/blog/${slugAndFullslug.slug}`;
3629
}
3730
return path;
3831
}

src/BlogData.mjs

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
4+
var data = [
5+
[
6+
"rescript-association-rebranding",
7+
"2021-03-03-rescript-association-rebranding"
8+
],
9+
[
10+
"release-9-0",
11+
"2021-02-09-release-9-0"
12+
],
13+
[
14+
"release-8-3-pt2",
15+
"2020-09-25-release-8-3-2"
16+
],
17+
[
18+
"release-8-3-pt1",
19+
"2020-09-25-release-8-3"
20+
],
21+
[
22+
"new-rescript-logo",
23+
"2020-08-28-new-rescript-logo"
24+
],
25+
[
26+
"bucklescript-is-rebranding",
27+
"2020-08-10-bucklescript-is-rebranding"
28+
],
29+
[
30+
"a-note-on-bucklescripts-future-commitments",
31+
"archive/a-note-on-bucklescripts-future-commitments"
32+
],
33+
[
34+
"a-small-step-for-bucklescript",
35+
"archive/a-small-step-for-bucklescript"
36+
],
37+
[
38+
"a-story-of-exception-encoding",
39+
"archive/a-story-of-exception-encoding"
40+
],
41+
[
42+
"a-story-of-lazy-encoding",
43+
"archive/a-story-of-lazy-encoding"
44+
],
45+
[
46+
"another-encoding",
47+
"archive/another-encoding"
48+
],
49+
[
50+
"arity-zero",
51+
"archive/arity-zero"
52+
],
53+
[
54+
"bucklescript-8-1-new-syntax",
55+
"archive/bucklescript-8-1-new-syntax"
56+
],
57+
[
58+
"bucklescript-release-1-0",
59+
"archive/bucklescript-release-1-0"
60+
],
61+
[
62+
"bucklescript-release-1-4-2",
63+
"archive/bucklescript-release-1-4-2"
64+
],
65+
[
66+
"bucklescript-release-1-4-3",
67+
"archive/bucklescript-release-1-4-3"
68+
],
69+
[
70+
"bucklescript-release-1-5-0",
71+
"archive/bucklescript-release-1-5-0"
72+
],
73+
[
74+
"bucklescript-release-1-5-1",
75+
"archive/bucklescript-release-1-5-1"
76+
],
77+
[
78+
"bucklescript-release-1-5-2",
79+
"archive/bucklescript-release-1-5-2"
80+
],
81+
[
82+
"bucklescript-release-1-7-0",
83+
"archive/bucklescript-release-1-7-0"
84+
],
85+
[
86+
"bucklescript-release-1-7-4",
87+
"archive/bucklescript-release-1-7-4"
88+
],
89+
[
90+
"bucklescript-release-1-7-5",
91+
"archive/bucklescript-release-1-7-5"
92+
],
93+
[
94+
"bucklescript-release-3-0-0",
95+
"archive/bucklescript-release-3-0-0"
96+
],
97+
[
98+
"bucklescript-release-3-1-0",
99+
"archive/bucklescript-release-3-1-0"
100+
],
101+
[
102+
"bucklescript-release-3-1-4",
103+
"archive/bucklescript-release-3-1-4"
104+
],
105+
[
106+
"bucklescript-release-4-0-0-pt1",
107+
"archive/bucklescript-release-4-0-0-pt1"
108+
],
109+
[
110+
"bucklescript-release-4-0-0-pt2",
111+
"archive/bucklescript-release-4-0-0-pt2"
112+
],
113+
[
114+
"bucklescript-release-4-0-17",
115+
"archive/bucklescript-release-4-0-17"
116+
],
117+
[
118+
"bucklescript-release-4-0-8",
119+
"archive/bucklescript-release-4-0-8"
120+
],
121+
[
122+
"bucklescript-release-5-0-1",
123+
"archive/bucklescript-release-5-0-1"
124+
],
125+
[
126+
"bucklescript-release-5-0-4",
127+
"archive/bucklescript-release-5-0-4"
128+
],
129+
[
130+
"bucklescript-release-5-0-5",
131+
"archive/bucklescript-release-5-0-5"
132+
],
133+
[
134+
"bucklescript-release-5-0",
135+
"archive/bucklescript-release-5-0"
136+
],
137+
[
138+
"bucklescript-release-5-1-0",
139+
"archive/bucklescript-release-5-1-0"
140+
],
141+
[
142+
"bucklescript-release-5-2-0",
143+
"archive/bucklescript-release-5-2-0"
144+
],
145+
[
146+
"bucklescript-release-6-0",
147+
"archive/bucklescript-release-6-0"
148+
],
149+
[
150+
"bucklescript-release-7-0-2",
151+
"archive/bucklescript-release-7-0-2"
152+
],
153+
[
154+
"bucklescript-release-7-1-0",
155+
"archive/bucklescript-release-7-1-0"
156+
],
157+
[
158+
"bucklescript-release-7-2",
159+
"archive/bucklescript-release-7-2"
160+
],
161+
[
162+
"bucklescript-release-7-3",
163+
"archive/bucklescript-release-7-3"
164+
],
165+
[
166+
"bucklescript-release-8-1-1",
167+
"archive/bucklescript-release-8-1-1"
168+
],
169+
[
170+
"bucklescript-release-8-2",
171+
"archive/bucklescript-release-8-2"
172+
],
173+
[
174+
"bucklescript-roadmap-q3-4-2018",
175+
"archive/bucklescript-roadmap-q3-4-2018"
176+
],
177+
[
178+
"feature-preview-variadic",
179+
"archive/feature-preview-variadic"
180+
],
181+
[
182+
"ffi-overview",
183+
"archive/ffi-overview"
184+
],
185+
[
186+
"generalize-uncurry",
187+
"archive/generalize-uncurry"
188+
],
189+
[
190+
"loading-stdlib-in-memory",
191+
"archive/loading-stdlib-in-memory"
192+
],
193+
[
194+
"overview-of-new_encoding",
195+
"archive/overview-of-new_encoding"
196+
],
197+
[
198+
"scalable",
199+
"archive/scalable"
200+
],
201+
[
202+
"state-of-reasonml-org-2020-q2-pt1",
203+
"archive/state-of-reasonml-org-2020-q2-pt1"
204+
],
205+
[
206+
"state-of-reasonml-org-2020-q2-pt2",
207+
"archive/state-of-reasonml-org-2020-q2-pt2"
208+
],
209+
[
210+
"state-of-reasonml-org-2020-q2-pt3",
211+
"archive/state-of-reasonml-org-2020-q2-pt3"
212+
],
213+
[
214+
"state-of-reasonml-org-2020-q2-pt4",
215+
"archive/state-of-reasonml-org-2020-q2-pt4"
216+
],
217+
[
218+
"string-literal-types-in-reason",
219+
"archive/string-literal-types-in-reason"
220+
],
221+
[
222+
"union-types-in-bucklescript",
223+
"archive/union-types-in-bucklescript"
224+
],
225+
[
226+
"whats-new-in-7-pt1",
227+
"archive/whats-new-in-7-pt1"
228+
],
229+
[
230+
"whats-new-in-7-pt2",
231+
"archive/whats-new-in-7-pt2"
232+
],
233+
[
234+
"editor-support-custom-operators-and-more",
235+
"2020-11-17-editor-support-custom-operators-and-more"
236+
],
237+
[
238+
"editor-support-release-1-0",
239+
"2020-11-26-editor-support-release-1-0"
240+
],
241+
[
242+
"bucklescript-release-8-4",
243+
"2020-12-07-release-8-4"
244+
]
245+
].map(function (param) {
246+
return {
247+
slug: param[0],
248+
fullslug: param[1]
249+
};
250+
});
251+
252+
export {
253+
data ,
254+
255+
}
256+
/* data Not a pure module */

0 commit comments

Comments
 (0)