diff --git a/lib/mdxUtils.ts b/lib/mdxUtils.ts index 908c5e7..c7de8bd 100644 --- a/lib/mdxUtils.ts +++ b/lib/mdxUtils.ts @@ -41,20 +41,21 @@ export function readMarkdownFile( slug: string, locale: string, type?: MARKDOWN_SUBFOLDER_TYPE -): MarkdownFile { +): MarkdownFile | undefined { const markdownFolderPath = getMarkdownFolderPathByTypeAndLocale(locale, type); const markdownFilePathForSlug = fs .readdirSync(markdownFolderPath) - .filter((file) => file.endsWith('.mdx') || file.endsWith('.md')) + .filter((path) => /\.mdx?$/.test(path)) .find((file) => file.startsWith(slug)); - if (!markdownFilePathForSlug) - throw new Error(`No markdown files found for given slug ${slug}`); + if (!markdownFilePathForSlug) { + return; + } const fullPath = path.join(markdownFolderPath, markdownFilePathForSlug); if (!fs.existsSync(fullPath)) { - throw new Error(`Markdown file not found for path ${path}`); + return; } const fileContents = fs.readFileSync(fullPath, 'utf8'); @@ -68,10 +69,15 @@ export function getMarkdownFrontmatterAndContent( fields: string[] = [], locale: string, type?: MARKDOWN_SUBFOLDER_TYPE -): MarkdownData { +): MarkdownData | undefined { const slug = filePath.replace(/\.mdx?$/, ''); - const { data, content } = readMarkdownFile(slug, locale, type); + const file = readMarkdownFile(slug, locale, type); + + if (!file) { + return; + } + const { content, data } = file; const markdownData: MarkdownData = {}; // Ensure only the minimal needed data is exposed for (const field of fields) { @@ -96,8 +102,9 @@ export function getAllMarkdownByDate( ): MarkdownData[] { const markdownPaths = getMarkdownPathsByTypeAndLocale(locale, type); const data = markdownPaths - .map((filePath) => - getMarkdownFrontmatterAndContent(filePath, fields, locale, type) + .map( + (filePath) => + getMarkdownFrontmatterAndContent(filePath, fields, locale, type)! ) .sort((item1, item2) => (item1.date > item2.date ? -1 : 1)); return data; @@ -121,5 +128,7 @@ export function getAllMarkdownSlugsForType( ?.map((slug) => slug.replace(/\.mdx?$/, '')); const uniqueSlugs = [...new Set(slugs)]; + console.log('LOLOL', uniqueSlugs); + return uniqueSlugs; } diff --git a/markdown/en/posts/cheatcheat.md b/markdown/en/posts/cheatsheet.md similarity index 99% rename from markdown/en/posts/cheatcheat.md rename to markdown/en/posts/cheatsheet.md index 6ce9e44..5ce9663 100644 --- a/markdown/en/posts/cheatcheat.md +++ b/markdown/en/posts/cheatsheet.md @@ -1,7 +1,7 @@ --- date: '2021-03-24' thumbnail: /assets/test.jpg -title: Cheatcheat +title: Cheatsheet description: The soup stock from sea kelp and dried bonito flakes can be used in many Japanese food such as miso soup, soba, udon, and stew. --- diff --git a/pages/posts/[slug].tsx b/pages/posts/[slug].tsx index 5cf87cf..e035c68 100644 --- a/pages/posts/[slug].tsx +++ b/pages/posts/[slug].tsx @@ -26,12 +26,15 @@ export default SingleBlog; SingleBlog.Layout = Layout; export const getStaticProps: GetStaticProps = async ({ params, locale }) => { - const { content, data } = readMarkdownFile( - params?.slug as string, - locale!, - 'posts' - ); + const file = readMarkdownFile(params?.slug as string, locale!, 'posts'); + + if (!file) { + return { + notFound: true, + }; + } + const { content, data } = file; const mdxSource = content ? await serialize(content, { scope: data }) : null; return { @@ -45,7 +48,6 @@ export const getStaticProps: GetStaticProps = async ({ params, locale }) => { export const getStaticPaths: GetStaticPaths = async ({ locales }) => { const slugs = getAllMarkdownSlugsForType(locales!, 'posts'); - const paths = slugs.flatMap((slug) => locales!.map((locale) => ({ params: { diff --git a/pages/privacy.tsx b/pages/privacy.tsx index e82f993..21e1247 100644 --- a/pages/privacy.tsx +++ b/pages/privacy.tsx @@ -27,8 +27,15 @@ export default PrivacyPage; PrivacyPage.Layout = Layout; export const getStaticProps: GetStaticProps = async ({ locale }) => { - const { content, data } = readMarkdownFile('privacybeleid', locale!); + const file = readMarkdownFile('privacybeleid', locale!); + if (!file) { + return { + notFound: true, + }; + } + + const { content, data } = file; const mdxSource = content ? await serialize(content, { scope: data }) : null; return { diff --git a/public/robots.txt b/public/robots.txt index 48f2646..1a276ce 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -3,7 +3,7 @@ User-agent: * Allow: / # Host -Host: https://example.com +Host: 'https://example.com', # Sitemaps -Sitemap: https://example.com/sitemap.xml +Sitemap: 'https://example.com',/sitemap.xml diff --git a/public/sitemap.xml b/public/sitemap.xml index 33fe18d..94ab4a4 100644 --- a/public/sitemap.xml +++ b/public/sitemap.xml @@ -1,27 +1,39 @@ -https://example.comdaily0.72021-05-26T18:35:09.678Z -https://example.com/500daily0.72021-05-26T18:35:09.679Z -https://example.com/blogdaily0.72021-05-26T18:35:09.679Z -https://example.com/buttonsdaily0.72021-05-26T18:35:09.679Z -https://example.com/formpagedaily0.72021-05-26T18:35:09.679Z -https://example.com/nl/404daily0.72021-05-26T18:35:09.679Z -https://example.com/en/404daily0.72021-05-26T18:35:09.679Z -https://example.com/fr/404daily0.72021-05-26T18:35:09.679Z -https://example.com/nldaily0.72021-05-26T18:35:09.679Z -https://example.com/endaily0.72021-05-26T18:35:09.679Z -https://example.com/frdaily0.72021-05-26T18:35:09.679Z -https://example.com/nl/500daily0.72021-05-26T18:35:09.679Z -https://example.com/en/500daily0.72021-05-26T18:35:09.679Z -https://example.com/fr/500daily0.72021-05-26T18:35:09.679Z -https://example.com/nl/formpagedaily0.72021-05-26T18:35:09.679Z -https://example.com/en/formpagedaily0.72021-05-26T18:35:09.679Z -https://example.com/fr/formpagedaily0.72021-05-26T18:35:09.679Z -https://example.com/nl/buttonsdaily0.72021-05-26T18:35:09.679Z -https://example.com/en/buttonsdaily0.72021-05-26T18:35:09.679Z -https://example.com/fr/buttonsdaily0.72021-05-26T18:35:09.679Z -https://example.com/nl/blogdaily0.72021-05-26T18:35:09.679Z -https://example.com/en/blogdaily0.72021-05-26T18:35:09.679Z -https://example.com/fr/blogdaily0.72021-05-26T18:35:09.679Z -https://example.com/nl/posts/exampledaily0.72021-05-26T18:35:09.679Z +'https://example.com',daily0.72021-12-19T15:20:43.498Z +'https://example.com',/500daily0.72021-12-19T15:20:43.498Z +'https://example.com',/blogdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/buttonsdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/formpagedaily0.72021-12-19T15:20:43.498Z +'https://example.com',/privacydaily0.72021-12-19T15:20:43.498Z +'https://example.com',/nldaily0.72021-12-19T15:20:43.498Z +'https://example.com',/endaily0.72021-12-19T15:20:43.498Z +'https://example.com',/frdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/nl/500daily0.72021-12-19T15:20:43.498Z +'https://example.com',/en/500daily0.72021-12-19T15:20:43.498Z +'https://example.com',/fr/500daily0.72021-12-19T15:20:43.498Z +'https://example.com',/nl/404daily0.72021-12-19T15:20:43.498Z +'https://example.com',/en/404daily0.72021-12-19T15:20:43.498Z +'https://example.com',/fr/404daily0.72021-12-19T15:20:43.498Z +'https://example.com',/nl/formpagedaily0.72021-12-19T15:20:43.498Z +'https://example.com',/en/formpagedaily0.72021-12-19T15:20:43.498Z +'https://example.com',/fr/formpagedaily0.72021-12-19T15:20:43.498Z +'https://example.com',/nl/buttonsdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/en/buttonsdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/fr/buttonsdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/nl/blogdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/en/blogdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/fr/blogdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/nl/privacydaily0.72021-12-19T15:20:43.498Z +'https://example.com',/en/privacydaily0.72021-12-19T15:20:43.498Z +'https://example.com',/fr/privacydaily0.72021-12-19T15:20:43.498Z +'https://example.com',/nl/posts/cheatsheetNLdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/en/posts/cheatsheetNLdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/fr/posts/cheatsheetNLdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/nl/posts/cheatsheetdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/en/posts/cheatsheetdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/fr/posts/cheatsheetdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/nl/posts/cheatsheetFRdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/en/posts/cheatsheetFRdaily0.72021-12-19T15:20:43.498Z +'https://example.com',/fr/posts/cheatsheetFRdaily0.72021-12-19T15:20:43.498Z \ No newline at end of file