Skip to content

Commit 6405c48

Browse files
authored
Merge pull request sveltejs#19 from sveltejs/simplify-dates
simplify date handling
2 parents e238bd8 + e1e84de commit 6405c48

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

src/transform/docs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ _docs("transforms blog", async () => {
7171
const output = await transform_blog(blog_in, "svelte", "blog");
7272
// console.log(output)
7373

74-
75-
74+
75+
7676
assert.equal(output.full[0].content, blog_out_full[0].content);
7777
assert.equal(output, { list: blog_out_list, full: blog_out_full });
7878
});

src/transform/docs.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const make_slug = make_session_slug_processor({
4747
separator: "-",
4848
});
4949

50+
const months = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');
51+
5052
export async function transform_blog(
5153
blogs: DocsSource[],
5254
project: string,
@@ -56,15 +58,15 @@ export async function transform_blog(
5658
const final_blog = (
5759
await Promise.all(
5860
blogs.map((doc, i) => {
59-
const match = /^(\d+-\d+-\d+)-(.+)\.md$/.exec(blogs[i].name);
61+
const match = /^(\d{4})-(\d{2})-(\d{2})-(.+)\.md$/.exec(blogs[i].name);
6062
if (!match)
6163
throw new Error(`Invalid filename for blog: '${blogs[i].name}'`);
6264

63-
const [, pubdate, slug] = match;
64-
const date = new Date(`${pubdate} EDT`);
65+
const [, y, m, d, slug] = match;
66+
6567
dates.push({
66-
pretty: date.toDateString(),
67-
numeric: pubdate,
68+
pretty: `${months[+m - 1]} ${+d} ${y}`,
69+
numeric: `${y}-${m}-${d}`,
6870
});
6971

7072
return format({
@@ -250,7 +252,7 @@ async function process_tutorial(
250252
const _example = {
251253
name: vfile.data.section_title,
252254
slug: slug,
253-
255+
254256
};
255257

256258
full.push({

0 commit comments

Comments
 (0)