Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,7 @@ NODE_ENV=production npx postcss styles/main.css -o test.css

## Writing Blog Posts

In case you are a blog author, please refer to our [guide on writing blog
posts](https://rescript-lang.org/blogpost-guide).

**Quick-takeaways:**

- Blogposts are located in `_blogposts`
- Author metadata is located in `data/blog_authors.mjs`
- Make sure to follow the file naming rules
In case you are a blog author, please refer to our [guide on writing blog posts](https://rescript-lang.org/blogpost-guide).

### Contributing

Expand Down
2 changes: 1 addition & 1 deletion _blogposts/2020-09-25-release-8-3-2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ It's focused on type safety, performance and JS interop. It used to be called Bu
npm i bs-platform@8.3.1
```

Following the [previous post](/blog/release-8-3-pt1), in this post we will go through
Following the [previous post](/blog/release-8-3), in this post we will go through
the enhancement over the build system.

## Performance enhancement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
author: hongbo
date: "2018-07-17 8:00"
date: "2018-07-17"
previewImg:
badge: release
title: Announcing BuckleScript 4.0 (Part One)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
author: hongbo
date: "2018-07-17 17:00"
date: "2018-07-17"
previewImg:
badge: release
title: Announcing BuckleScript 4.0 (Part Two)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
author: hongbo
date: "2019-03-1"
date: "2019-03-01"
previewImg:
badge: preview
title: First-class bs.variadic Support in the Next Release
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
author: hongbo
date: "2020-05-06 18:00"
date: "2020-05-06"
previewImg:
title: New Exception Encoding in BuckleScript
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
author: hongbo
date: "2020-05-15 18:00"
date: "2020-05-15"
previewImg:
title: New Lazy Encoding in BuckleScript
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
author: hongbo
date: "2020-06-22 18:00"
date: "2020-06-22"
previewImg:
title: Make generated JavaScript Inline Caching friendly using types in BuckleScript version 8
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
author: hongbo
date: "2020-07-28 18:00"
date: "2020-07-28"
previewImg:
title: Introducing string literal types in BuckleScript version 8.2
description: |
Expand Down
13 changes: 7 additions & 6 deletions pages/blogpost-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ Open the [localhost:3000/blog](/blog) page to see the blog page.

## Create a new file

Blogposts are located in the `./_blogposts` directory.
Please stick to the following filename convention to maintain a natural sort order on every file-system:
Blogposts are located in the `./_blogposts` directory. File name starts with the date to maintain a natural sort order:

```
_blogposts/YYYY-MM-DD-[title].mdx
Expand All @@ -28,14 +27,16 @@ touch _blogposts/2020-01-30-my-new-blog-post.mdx

### Map the file to a URL

Open the `src/BlogData.res` file and add a new mapping like this:
Open the `src/BlogData.res` file and add the path to `data`:

```res
("my-new-blog-post", "2020-01-30-my-new-blog-post.mdx")
let data = [
// ...
"2020-01-30-my-new-blog-post",
// ...
]
```

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.

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!

## Add Frontmatter Data
Expand Down
7 changes: 4 additions & 3 deletions scripts/test-hrefs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import fs from "fs";
import urlModule from "url";
import { URL } from 'url';
import {data as blogIndex} from '../src/BlogData.mjs'
import {getSlugFromPath} from '../src/common/BlogApi.mjs'

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

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

if (match) {
let relPath = match[1];
let slugAndFullslug = blogIndex.find(({fullslug}) => fullslug === relPath);
if (slugAndFullslug != null) {
return `./pages/blog/${slugAndFullslug.slug}`;
let path = blogIndex.find((path) => path === relPath);
if (path != null) {
return `./pages/blog/${getSlugFromPath(path)}`;
}
return path;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function getStaticProps(_ctx) {
var archived = acc[2];
var malformed = acc[1];
var posts = acc[0];
var id = postData.slug;
var id = BlogApi.getSlugFromPath(postData.path);
var decoded = BlogFrontmatter.decode(postData.frontmatter);
if (decoded.TAG === /* Ok */0) {
var frontmatter = decoded._0;
Expand Down
2 changes: 1 addition & 1 deletion src/Blog.res
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ let getStaticProps: Next.GetStaticProps.t<props, params> = _ctx => {
postData,
) => {
let (posts, malformed, archived) = acc
let id = postData.slug
let id = BlogApi.getSlugFromPath(postData.path)

let decoded = BlogFrontmatter.decode(postData.frontmatter)

Expand Down
18 changes: 11 additions & 7 deletions src/BlogArticle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as Util from "./common/Util.mjs";
import * as React from "react";
import * as BlogApi from "./common/BlogApi.mjs";
import * as DateStr from "./common/DateStr.mjs";
import * as BlogData from "./BlogData.mjs";
import * as Markdown from "./components/Markdown.mjs";
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
import * as MainLayout from "./layouts/MainLayout.mjs";
Expand Down Expand Up @@ -109,9 +110,9 @@ function BlogArticle$BlogHeader(Props) {
}

function $$default(props) {
var fullslug = props.fullslug;
var module_ = require("../_blogposts/" + (fullslug + ".mdx"));
var archived = fullslug.startsWith("archive/");
var path = props.path;
var module_ = require("../_blogposts/" + (path + ".mdx"));
var archived = path.startsWith("archive/");
var component = module_.default;
var fm = BlogFrontmatter.decode(frontmatter(component));
var children = React.createElement(component, {});
Expand Down Expand Up @@ -182,7 +183,7 @@ function $$default(props) {
children: null
}, React.createElement("h2", {
className: "font-bold text-gray-95 text-28 mb-2"
}, "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", {
}, "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", {
className: "font-bold mt-4"
}, "Errors:"), fm._0));
}
Expand All @@ -193,9 +194,12 @@ function $$default(props) {

function getStaticProps(ctx) {
var params = ctx.params;
var fullslug = Belt_Option.getWithDefault(BlogApi.getFullSlug(params.slug), params.slug);
var slug = BlogData.data.find(function (path2) {
return BlogApi.getSlugFromPath(path2) === params.slug;
});
var path = slug !== undefined ? slug : params.slug;
var props = {
fullslug: fullslug
path: path
};
return Promise.resolve({
props: props
Expand All @@ -206,7 +210,7 @@ function getStaticPaths(param) {
var paths = Belt_Array.map(BlogApi.getAllPosts(undefined), (function (postData) {
return {
params: {
slug: postData.slug
slug: BlogApi.getSlugFromPath(postData.path)
}
};
}));
Expand Down
21 changes: 13 additions & 8 deletions src/BlogArticle.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Params = {
type t = {slug: string}
}

type props = {fullslug: string}
type props = {path: string}

module BlogComponent = {
type t = {default: React.component<{.}>}
Expand Down Expand Up @@ -124,11 +124,11 @@ module BlogHeader = {
}

let default = (props: props) => {
let {fullslug} = props
let {path} = props

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

let archived = Js.String2.startsWith(fullslug, "archive/")
let archived = Js.String2.startsWith(path, "archive/")

let component = module_.default

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

let fullslug = BlogApi.getFullSlug(params.slug)->Belt.Option.getWithDefault(params.slug)
let path = switch BlogData.data->Js.Array2.find(path2 =>
BlogApi.getSlugFromPath(path2) == params.slug
) {
| None => params.slug
| Some(slug) => slug
}

let props = {fullslug: fullslug}
let props = {path: path}
let ret = {"props": props}
Promise.resolve(ret)
}
Expand All @@ -237,7 +242,7 @@ let getStaticPaths: Next.GetStaticPaths.t<Params.t> = () => {

let paths = BlogApi.getAllPosts()->Belt.Array.map(postData => {
params: {
Params.slug: postData.slug,
Params.slug: BlogApi.getSlugFromPath(postData.path),
},
})
let ret = {paths: paths, fallback: false}
Expand Down
2 changes: 1 addition & 1 deletion src/BlogArticle.resi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Params: {
type t = {slug: string}
}

type props = {fullslug: string}
type props = {path: string}

let default: props => React.element

Expand Down
Loading