implemented korean unsearchable posts

This commit is contained in:
Kim, Jimin 2022-03-26 23:12:47 +09:00
parent 843b7d2829
commit 3f2f48798b
3 changed files with 40 additions and 21 deletions

View file

@ -62,13 +62,16 @@ export default function parseMarkdown(
path: string, path: string,
mode: ParseMode mode: ParseMode
): MarkdownData { ): MarkdownData {
// todo: accurately calculate start and end of front matter const fileHasFrontMatter = markdownRaw.startsWith("---")
const frontMatter = markdownRaw.startsWith("---")
const frontMatter = fileHasFrontMatter
? matter(markdownRaw.slice(0, nthIndex(markdownRaw, "---", 2) + 3)).data ? matter(markdownRaw.slice(0, nthIndex(markdownRaw, "---", 2) + 3)).data
: {} : {}
if (fileHasFrontMatter) {
if (mode != ParseMode.PORTFOLIO) { if (mode != ParseMode.PORTFOLIO) {
if (!frontMatter.title) throw Error(`Title is not defined in file: ${path}`) if (!frontMatter.title)
throw Error(`Title is not defined in file: ${path}`)
if (mode != ParseMode.UNSEARCHABLE && !frontMatter.date) if (mode != ParseMode.UNSEARCHABLE && !frontMatter.date)
throw Error(`Date is not defined in file: ${path}`) throw Error(`Date is not defined in file: ${path}`)
@ -79,6 +82,7 @@ export default function parseMarkdown(
frontMatter.overview = md.render(frontMatter.overview) frontMatter.overview = md.render(frontMatter.overview)
} }
} }
}
// //
// work with rendered DOM // work with rendered DOM
@ -86,7 +90,7 @@ export default function parseMarkdown(
const dom = new JSDOM( const dom = new JSDOM(
md.render( md.render(
markdownRaw.startsWith("---") fileHasFrontMatter
? markdownRaw.slice(nthIndex(markdownRaw, "---", 2) + 3) ? markdownRaw.slice(nthIndex(markdownRaw, "---", 2) + 3)
: markdownRaw : markdownRaw
) || "" ) || ""

View file

@ -10,6 +10,7 @@ export default function parseUnsearchable(data: DataToPass): void {
// convert path like /XXX/YYY/ZZZ to /YYY/ZZZ // convert path like /XXX/YYY/ZZZ to /YYY/ZZZ
const urlPath = _urlPath.slice(_urlPath.slice(1).indexOf("/") + 1) const urlPath = _urlPath.slice(_urlPath.slice(1).indexOf("/") + 1)
if (!urlPath.endsWith(".kr.md")) {
addDocument({ addDocument({
title: markdownData.title, title: markdownData.title,
body: markdownData.content, body: markdownData.content,
@ -20,6 +21,7 @@ export default function parseUnsearchable(data: DataToPass): void {
map.unsearchable[urlPath] = { map.unsearchable[urlPath] = {
title: markdownData.title as string, title: markdownData.title as string,
} }
}
/** /**
* Save content * Save content

View file

@ -61,7 +61,17 @@ const fetchContent = async (
) => { ) => {
try { try {
if (pageType == PageType.UNSEARCHABLE) { if (pageType == PageType.UNSEARCHABLE) {
if (locale == "en") {
return await import(`../../data/content/unsearchable${url}.json`) return await import(`../../data/content/unsearchable${url}.json`)
} else {
try {
return await import(
`../../data/content/unsearchable${url}.${locale}.json`
)
} catch {
return await import(`../../data/content/unsearchable${url}.json`)
}
}
} }
if (locale == "en") { if (locale == "en") {
@ -260,7 +270,10 @@ const Page = () => {
} }
case PageType.UNSEARCHABLE: { case PageType.UNSEARCHABLE: {
pageData.title = map.unsearchable[url].title pageData.title = (
map.unsearchable[`${url}.${globalState.locale}`] ||
map.unsearchable[url]
).title
pageData.content = fetched_content.content pageData.content = fetched_content.content
break break