Skip to content

Commit ff5000f

Browse files
authored
clean blog links (#355)
* Rename blog posts to include date * Make apis cater to that * Clean up * fullslug -> path * Update readmes
1 parent 905351e commit ff5000f

File tree

65 files changed

+190
-402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+190
-402
lines changed

README.md

Lines changed: 1 addition & 8 deletions

_blogposts/2020-09-25-release-8-3-2.mdx

Lines changed: 1 addition & 1 deletion

_blogposts/archive/bucklescript-release-4-0-0-pt1.mdx renamed to _blogposts/archive/2018-07-17-bucklescript-release-4-0-0-pt1.mdx

Lines changed: 1 addition & 1 deletion

_blogposts/archive/bucklescript-release-4-0-0-pt2.mdx renamed to _blogposts/archive/2018-07-17-bucklescript-release-4-0-0-pt2.mdx

Lines changed: 1 addition & 1 deletion

_blogposts/archive/feature-preview-variadic.mdx renamed to _blogposts/archive/2019-03-01-feature-preview-variadic.mdx

Lines changed: 1 addition & 1 deletion

_blogposts/archive/a-story-of-exception-encoding.mdx renamed to _blogposts/archive/2020-05-06-a-story-of-exception-encoding.mdx

Lines changed: 1 addition & 1 deletion

_blogposts/archive/a-story-of-lazy-encoding.mdx renamed to _blogposts/archive/2020-05-15-a-story-of-lazy-encoding.mdx

Lines changed: 1 addition & 1 deletion

_blogposts/archive/overview-of-new_encoding.mdx renamed to _blogposts/archive/2020-06-22-overview-of-new_encoding.mdx

Lines changed: 1 addition & 1 deletion

_blogposts/archive/string-literal-types-in-reason.mdx renamed to _blogposts/archive/2020-07-28-string-literal-types-in-reason.mdx

Lines changed: 1 addition & 1 deletion

pages/blogpost-guide.mdx

Lines changed: 7 additions & 6 deletions

scripts/test-hrefs.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import fs from "fs";
1515
import urlModule from "url";
1616
import { URL } from 'url';
1717
import {data as blogIndex} from '../src/BlogData.mjs'
18+
import {getSlugFromPath} from '../src/common/BlogApi.mjs'
1819

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

@@ -23,9 +24,9 @@ const mapBlogFilePath = path => {
2324

2425
if (match) {
2526
let relPath = match[1];
26-
let slugAndFullslug = blogIndex.find(({fullslug}) => fullslug === relPath);
27-
if (slugAndFullslug != null) {
28-
return `./pages/blog/${slugAndFullslug.slug}`;
27+
let path = blogIndex.find((path) => path === relPath);
28+
if (path != null) {
29+
return `./pages/blog/${getSlugFromPath(path)}`;
2930
}
3031
return path;
3132
}

src/Blog.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ function getStaticProps(_ctx) {
323323
var archived = acc[2];
324324
var malformed = acc[1];
325325
var posts = acc[0];
326-
var id = postData.slug;
326+
var id = BlogApi.getSlugFromPath(postData.path);
327327
var decoded = BlogFrontmatter.decode(postData.frontmatter);
328328
if (decoded.TAG === /* Ok */0) {
329329
var frontmatter = decoded._0;

src/Blog.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ let getStaticProps: Next.GetStaticProps.t<props, params> = _ctx => {
372372
postData,
373373
) => {
374374
let (posts, malformed, archived) = acc
375-
let id = postData.slug
375+
let id = BlogApi.getSlugFromPath(postData.path)
376376

377377
let decoded = BlogFrontmatter.decode(postData.frontmatter)
378378

src/BlogArticle.mjs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as Util from "./common/Util.mjs";
99
import * as React from "react";
1010
import * as BlogApi from "./common/BlogApi.mjs";
1111
import * as DateStr from "./common/DateStr.mjs";
12+
import * as BlogData from "./BlogData.mjs";
1213
import * as Markdown from "./components/Markdown.mjs";
1314
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
1415
import * as MainLayout from "./layouts/MainLayout.mjs";
@@ -109,9 +110,9 @@ function BlogArticle$BlogHeader(Props) {
109110
}
110111

111112
function $$default(props) {
112-
var fullslug = props.fullslug;
113-
var module_ = require("../_blogposts/" + (fullslug + ".mdx"));
114-
var archived = fullslug.startsWith("archive/");
113+
var path = props.path;
114+
var module_ = require("../_blogposts/" + (path + ".mdx"));
115+
var archived = path.startsWith("archive/");
115116
var component = module_.default;
116117
var fm = BlogFrontmatter.decode(frontmatter(component));
117118
var children = React.createElement(component, {});
@@ -182,7 +183,7 @@ function $$default(props) {
182183
children: null
183184
}, React.createElement("h2", {
184185
className: "font-bold text-gray-95 text-28 mb-2"
185-
}, "Could not parse file '_blogposts/" + (fullslug + ".mdx'")), React.createElement("p", undefined, "The content of this blog post will be displayed as soon as all\n required frontmatter data has been added."), React.createElement("p", {
186+
}, "Could not parse file '_blogposts/" + (path + ".mdx'")), React.createElement("p", undefined, "The content of this blog post will be displayed as soon as all\n required frontmatter data has been added."), React.createElement("p", {
186187
className: "font-bold mt-4"
187188
}, "Errors:"), fm._0));
188189
}
@@ -193,9 +194,12 @@ function $$default(props) {
193194

194195
function getStaticProps(ctx) {
195196
var params = ctx.params;
196-
var fullslug = Belt_Option.getWithDefault(BlogApi.getFullSlug(params.slug), params.slug);
197+
var slug = BlogData.data.find(function (path2) {
198+
return BlogApi.getSlugFromPath(path2) === params.slug;
199+
});
200+
var path = slug !== undefined ? slug : params.slug;
197201
var props = {
198-
fullslug: fullslug
202+
path: path
199203
};
200204
return Promise.resolve({
201205
props: props
@@ -206,7 +210,7 @@ function getStaticPaths(param) {
206210
var paths = Belt_Array.map(BlogApi.getAllPosts(undefined), (function (postData) {
207211
return {
208212
params: {
209-
slug: postData.slug
213+
slug: BlogApi.getSlugFromPath(postData.path)
210214
}
211215
};
212216
}));

src/BlogArticle.res

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Params = {
2222
type t = {slug: string}
2323
}
2424

25-
type props = {fullslug: string}
25+
type props = {path: string}
2626

2727
module BlogComponent = {
2828
type t = {default: React.component<{.}>}
@@ -124,11 +124,11 @@ module BlogHeader = {
124124
}
125125

126126
let default = (props: props) => {
127-
let {fullslug} = props
127+
let {path} = props
128128

129-
let module_ = BlogComponent.require("../_blogposts/" ++ (fullslug ++ ".mdx"))
129+
let module_ = BlogComponent.require("../_blogposts/" ++ (path ++ ".mdx"))
130130

131-
let archived = Js.String2.startsWith(fullslug, "archive/")
131+
let archived = Js.String2.startsWith(path, "archive/")
132132

133133
let component = module_.default
134134

@@ -207,7 +207,7 @@ let default = (props: props) => {
207207
<div>
208208
<Markdown.Warn>
209209
<h2 className="font-bold text-gray-95 text-28 mb-2">
210-
{React.string("Could not parse file '_blogposts/" ++ (fullslug ++ ".mdx'"))}
210+
{React.string("Could not parse file '_blogposts/" ++ (path ++ ".mdx'"))}
211211
</h2>
212212
<p>
213213
{React.string("The content of this blog post will be displayed as soon as all
@@ -225,9 +225,14 @@ let getStaticProps: Next.GetStaticProps.t<props, Params.t> = ctx => {
225225
open Next.GetStaticProps
226226
let {params} = ctx
227227

228-
let fullslug = BlogApi.getFullSlug(params.slug)->Belt.Option.getWithDefault(params.slug)
228+
let path = switch BlogData.data->Js.Array2.find(path2 =>
229+
BlogApi.getSlugFromPath(path2) == params.slug
230+
) {
231+
| None => params.slug
232+
| Some(slug) => slug
233+
}
229234

230-
let props = {fullslug: fullslug}
235+
let props = {path: path}
231236
let ret = {"props": props}
232237
Promise.resolve(ret)
233238
}
@@ -237,7 +242,7 @@ let getStaticPaths: Next.GetStaticPaths.t<Params.t> = () => {
237242

238243
let paths = BlogApi.getAllPosts()->Belt.Array.map(postData => {
239244
params: {
240-
Params.slug: postData.slug,
245+
Params.slug: BlogApi.getSlugFromPath(postData.path),
241246
},
242247
})
243248
let ret = {paths: paths, fallback: false}

src/BlogArticle.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Params: {
22
type t = {slug: string}
33
}
44

5-
type props = {fullslug: string}
5+
type props = {path: string}
66

77
let default: props => React.element
88

0 commit comments

Comments
 (0)