Skip to content

Commit

Permalink
Use current frontmatter template
Browse files Browse the repository at this point in the history
There's a pending change to update some new frontmatter keywords, the tool should cont to use the older keywords. (e.g. `dateline_str` vs `date`)
  • Loading branch information
TomNUSDS committed Mar 1, 2024
1 parent 588093c commit 60293eb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
left: 5px;
z-index: 100;
}

.cm-searchMatch {
background-color: rgba(250, 247, 2, 0.27) !important;
}
30 changes: 28 additions & 2 deletions src/mdxcomponents/frontmatterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,21 @@ export const yamlToBlogFields = (yamlstr: string): BlogFrontMatterFields => {
return result;
}


export const getYamlBlogHeader = (fields: BlogFrontMatterFields): string => {
/** there's a pending change with the website to rename some fields */
export const getYamlBlogHeaderNew = (fields: BlogFrontMatterFields): string => {
const tags = '[' + fields.tags?.map(s => `'${s}'`).join(',') + ']';
return `# Page template info (DO NOT EDIT)
layout: default
blog_page: true
# Carousel (Edit this)
carousel_title: "${fields.carousel_title}"
carousel_summary: "${fields.carousel_summary}"
# partial path to image
carousel_image: ${fields.carousel_image}
# accessibility text for image
carousel_image_alt_text: "${fields.carousel_image_alt_text}"
# should show on news and blog page. ordered by date prefix in filename
carousel_show: ${fields.carousel_show ? "true" : "false"}
# Blog detail page (Edit this)
title: "${fields.title}"
Expand All @@ -69,6 +78,14 @@ author: "${fields.author}"
permalink: ${fields.permalink}
basename: "${fields.basename}"
tags: [${tags}]
`;
}

export const getYamlBlogHeader = (fields: BlogFrontMatterFields): string => {
const tags = '[' + fields.tags?.map(s => `'${s}'`).join(',') + ']';
return `# Page template info (DO NOT EDIT)
layout: default
blog_page: true
# Carousel (Edit this)
carousel_title: "${fields.carousel_title}"
Expand All @@ -79,6 +96,15 @@ carousel_image: ${fields.carousel_image}
carousel_image_alt_text: "${fields.carousel_image_alt_text}"
# should show on news and blog page. ordered by date prefix in filename
carousel_show: ${fields.carousel_show ? "true" : "false"}
# Blog detail page (Edit this)
title: "${fields.title}"
dateline_str: "${fields.date}"
readtime_str: "${fields.readtime_minutes}"
byline_str: author: "${fields.author}"
permalink: ${fields.permalink}
basename: "${fields.basename}"
tags: [${tags}]
`;
}

Expand Down
19 changes: 11 additions & 8 deletions src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ export const getFilnamePartOfUrlPath = (pathstr?: string) => pathstr?.split("/")
export const forceTypeBoolean = (value: string | null | boolean): boolean | null =>
typeof value === 'boolean' ? value : value === 'true' ? true : value === 'false' ? false : null;

export const toUTCDate = (dateStr: string | Date): string => {
export const toUTCDate = (date: string | Date | undefined): string => {
if ((typeof date === "string") && (date.trim().length === 0 || date === "Invalid date")) {
date = undefined;
}
// have to be careful of the timezone shifting days because of UTC offsets.
// e.g. Date("1/1/2020") gets turned into "Dec 31, 2019"
// But "Jan 1, 2020" doesn't get converted. Such a horrible API.
// so, we're using moment.js
const dateObj = moment(dateStr);
const dateObj = moment(date);
return dateObj.toISOString().split("T")[0] || ""
}

Expand All @@ -33,13 +36,13 @@ export const shortDateToNanoId = (dateStr: string): string => {
// `0123456789abcdefghijklmnopqrstu` `vwxyz`
// Timestamp often starts the same leading character and ends with "0" so just remove.
// `lqw277k0` => `qw277k`
tempresult.replace('a','v')
tempresult.replace('a', 'v')
return tempresult
.replace('a','v')
.replace('e','w')
.replace('i','x')
.replace('o','z')
.substring(1, tempresult.length-1);
.replace('a', 'v')
.replace('e', 'w')
.replace('i', 'x')
.replace('o', 'z')
.substring(1, tempresult.length - 1);
}

export const cleanupFilename = (instr: string): string => {
Expand Down

0 comments on commit 60293eb

Please sign in to comment.