Skip to content

Commit

Permalink
Fix build breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
LeunensMichiel committed Dec 19, 2021
1 parent fd7dfc0 commit 1926a4a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 43 deletions.
27 changes: 18 additions & 9 deletions lib/mdxUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -121,5 +128,7 @@ export function getAllMarkdownSlugsForType(
?.map((slug) => slug.replace(/\.mdx?$/, ''));
const uniqueSlugs = [...new Set(slugs)];

console.log('LOLOL', uniqueSlugs);

return uniqueSlugs;
}
Original file line number Diff line number Diff line change
@@ -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.
---

Expand Down
14 changes: 8 additions & 6 deletions pages/posts/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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: {
Expand Down
9 changes: 8 additions & 1 deletion pages/privacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions public/robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
60 changes: 36 additions & 24 deletions public/sitemap.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url><loc>https://example.com</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.678Z</lastmod></url>
<url><loc>https://example.com/500</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/blog</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/buttons</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/formpage</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/nl/404</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/en/404</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/fr/404</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/nl</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/en</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/fr</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/nl/500</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/en/500</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/fr/500</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/nl/formpage</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/en/formpage</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/fr/formpage</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/nl/buttons</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/en/buttons</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/fr/buttons</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/nl/blog</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/en/blog</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/fr/blog</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>https://example.com/nl/posts/example</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-05-26T18:35:09.679Z</lastmod></url>
<url><loc>'https://example.com',</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/500</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/blog</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/buttons</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/formpage</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/privacy</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/nl</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/en</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/fr</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/nl/500</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/en/500</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/fr/500</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/nl/404</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/en/404</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/fr/404</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/nl/formpage</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/en/formpage</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/fr/formpage</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/nl/buttons</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/en/buttons</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/fr/buttons</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/nl/blog</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/en/blog</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/fr/blog</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/nl/privacy</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/en/privacy</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/fr/privacy</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/nl/posts/cheatsheetNL</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/en/posts/cheatsheetNL</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/fr/posts/cheatsheetNL</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/nl/posts/cheatsheet</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/en/posts/cheatsheet</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/fr/posts/cheatsheet</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/nl/posts/cheatsheetFR</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/en/posts/cheatsheetFR</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
<url><loc>'https://example.com',/fr/posts/cheatsheetFR</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-19T15:20:43.498Z</lastmod></url>
</urlset>

0 comments on commit 1926a4a

Please sign in to comment.