Skip to content

Commit

Permalink
Fix modifiedAt timestamp formatting
Browse files Browse the repository at this point in the history
- this is a bit of a hack, not sure why the dates appear to be offset from 1991 /shrug
  • Loading branch information
solomonhawk committed Sep 7, 2022
1 parent 7669ce2 commit f1767d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions scripts/import-from-bear/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function parsePost(post: DBPost): O.Option<PostData> {
const postData: PostData = {
title: post.title,
markdown: post.markdown,
publishDate: new Date(post.modifiedAt).toISOString(), // @TODO: fix this date
publishDate: postDate(post.modifiedAt),
tags: filterBearTags(JSON.parse(post.tags) || [])
};

Expand All @@ -36,6 +36,12 @@ export function parsePost(post: DBPost): O.Option<PostData> {
return O.none;
}

function postDate(date: number): string {
const d = new Date(date);
d.setHours(0, 0, 0, 0);
return d.toISOString();
}

function filterBearTags(tags: string[]): string[] {
return tags.map(tag => tag.replace(/^(blog\/solomonhawk\/?)|(blog\/?)/, '')).filter(Boolean).filter(tag => tag !== 'published');
}
Expand Down Expand Up @@ -77,7 +83,7 @@ function stripNoteTitle(markdown: string): string {
* @returns string with Bear tags removed
*/
function stripBearTags(markdown: string): string {
return markdown.replace(/\B#[\w\/]+\b/gm, '');
return markdown.replace(/(?<!`)\B#[\w\/]+\b/gm, '');
}

export function writePostAsMarkdown({filename, markdown}: { filename: string, markdown: string }): void {
Expand Down
4 changes: 2 additions & 2 deletions scripts/import-from-bear/query-posts-tags.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SELECT n.ZTITLE as title, n.ZTEXT as markdown, n.ZMODIFICATIONDATE as modifiedAt, json_group_array(t.ZTITLE) AS tags
SELECT n.ZTITLE as title, n.ZTEXT as markdown, datetime(n.ZMODIFICATIONDATE, 'unixepoch', '+31 years') as modifiedAt, json_group_array(t.ZTITLE) AS tags
FROM ZSFNOTE n
JOIN Z_7TAGS as nt ON nt.Z_7NOTES = n.Z_PK
JOIN ZSFNOTETAG as t ON nt.Z_14TAGS = t.Z_PK
GROUP BY n.ZTITLE, n.ZTEXT
HAVING tags LIKE '%blog/solomonhawk%';
HAVING tags LIKE '%blog/solomonhawk%';
2 changes: 1 addition & 1 deletion src/pages/writing/posts/hello-world.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: '@layouts/BlogPost.astro'
title: Hello, World!
publishDate: 2022-09-01T00:00:00.000Z
publishDate: 2022-09-01T04:00:00.000Z
---

import Counter from '@components/Counter.tsx'
Expand Down

0 comments on commit f1767d4

Please sign in to comment.