Skip to content

Commit 1a183f4

Browse files
authored
Better api name (#356)
1 parent ff5000f commit 1a183f4

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

scripts/test-hrefs.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +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'
18+
import {blogPathToSlug} from '../src/common/BlogApi.mjs'
1919

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

@@ -26,7 +26,7 @@ const mapBlogFilePath = path => {
2626
let relPath = match[1];
2727
let path = blogIndex.find((path) => path === relPath);
2828
if (path != null) {
29-
return `./pages/blog/${getSlugFromPath(path)}`;
29+
return `./pages/blog/${blogPathToSlug(path)}`;
3030
}
3131
return path;
3232
}

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 = BlogApi.getSlugFromPath(postData.path);
326+
var id = BlogApi.blogPathToSlug(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 = BlogApi.getSlugFromPath(postData.path)
375+
let id = BlogApi.blogPathToSlug(postData.path)
376376

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

src/BlogArticle.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function $$default(props) {
195195
function getStaticProps(ctx) {
196196
var params = ctx.params;
197197
var slug = BlogData.data.find(function (path2) {
198-
return BlogApi.getSlugFromPath(path2) === params.slug;
198+
return BlogApi.blogPathToSlug(path2) === params.slug;
199199
});
200200
var path = slug !== undefined ? slug : params.slug;
201201
var props = {
@@ -210,7 +210,7 @@ function getStaticPaths(param) {
210210
var paths = Belt_Array.map(BlogApi.getAllPosts(undefined), (function (postData) {
211211
return {
212212
params: {
213-
slug: BlogApi.getSlugFromPath(postData.path)
213+
slug: BlogApi.blogPathToSlug(postData.path)
214214
}
215215
};
216216
}));

src/BlogArticle.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ let getStaticProps: Next.GetStaticProps.t<props, Params.t> = ctx => {
226226
let {params} = ctx
227227

228228
let path = switch BlogData.data->Js.Array2.find(path2 =>
229-
BlogApi.getSlugFromPath(path2) == params.slug
229+
BlogApi.blogPathToSlug(path2) == params.slug
230230
) {
231231
| None => params.slug
232232
| Some(slug) => slug
@@ -242,7 +242,7 @@ let getStaticPaths: Next.GetStaticPaths.t<Params.t> = () => {
242242

243243
let paths = BlogApi.getAllPosts()->Belt.Array.map(postData => {
244244
params: {
245-
Params.slug: BlogApi.getSlugFromPath(postData.path),
245+
Params.slug: BlogApi.blogPathToSlug(postData.path),
246246
},
247247
})
248248
let ret = {paths: paths, fallback: false}

src/common/BlogApi.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as Caml_option from "rescript/lib/es6/caml_option.js";
1111
import GrayMatter from "gray-matter";
1212
import * as BlogFrontmatter from "./BlogFrontmatter.mjs";
1313

14-
function getSlugFromPath(path) {
14+
function blogPathToSlug(path) {
1515
return path.replace(/(archive\/)?\d\d\d\d-\d\d-\d\d-/, "");
1616
}
1717

@@ -50,7 +50,7 @@ function getLatest(maxOpt, baseUrlOpt, param) {
5050
var fm$1 = fm._0;
5151
var description = Belt_Option.getWithDefault(Caml_option.null_to_opt(fm$1.description), "");
5252
var item_title = fm$1.title;
53-
var item_href = baseUrl + ("/blog/" + getSlugFromPath(next.path));
53+
var item_href = baseUrl + ("/blog/" + blogPathToSlug(next.path));
5454
var item_pubDate = DateStr.toDate(fm$1.date);
5555
var item = {
5656
title: item_title,
@@ -96,7 +96,7 @@ var RssFeed = {
9696

9797
export {
9898
getAllPosts ,
99-
getSlugFromPath ,
99+
blogPathToSlug ,
100100
RssFeed ,
101101

102102
}

src/common/BlogApi.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type postData = {
3939
frontmatter: Js.Json.t,
4040
}
4141

42-
let getSlugFromPath = path => {
42+
let blogPathToSlug = path => {
4343
path->Js.String2.replaceByRe(%re(`/(archive\/)?\d\d\d\d-\d\d-\d\d-/`), "")
4444
}
4545

@@ -107,7 +107,7 @@ module RssFeed = {
107107
let description = Js.Null.toOption(fm.description)->Belt.Option.getWithDefault("")
108108
let item = {
109109
title: fm.title,
110-
href: baseUrl ++ ("/blog/" ++ getSlugFromPath(next.path)),
110+
href: baseUrl ++ ("/blog/" ++ blogPathToSlug(next.path)),
111111
description: description,
112112
pubDate: DateStr.toDate(fm.date),
113113
}

src/common/BlogApi.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type postData = {
66
}
77

88
let getAllPosts: unit => array<postData>
9-
let getSlugFromPath: string => string
9+
let blogPathToSlug: string => string
1010

1111
module RssFeed: {
1212
type item = {

0 commit comments

Comments
 (0)