Skip to content

Commit

Permalink
[blog] Fix missing card
Browse files Browse the repository at this point in the history
See how https://twitter.com/MUI_hq/status/1688919247504957440 doesn't have a card.
It's a follow-up on #38258.

I think that we should be able to fail the build if the card is missing, but too lazy.
  • Loading branch information
oliviertassinari committed Sep 6, 2023
1 parent d0a82a6 commit fe0d99d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/pages/blog/discord-announcement.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tags: ['News']
card: true
---

<a href="https://mui.com/r/discord/"><img src="/static/blog/2023-discord-announcement/discord.png" width="1280" height="640" style="margin-bottom: 16px;" alt="Discord banner with link" /></a>
<a href="https://mui.com/r/discord/"><img src="/static/blog/discord-announcement/discord.png" width="1280" height="640" style="margin-bottom: 16px;" alt="Discord banner with link" /></a>

This year, one of our highest priorities has been to create a central hub for the MUI community.
Up until now, our community has been scattered across discussions and interactions on [Twitter](https://twitter.com/MUI_hq), [LinkedIn](https://linkedin.com/company/mui), [GitHub](https://github.com/mui), and [Stack Overflow](https://stackoverflow.com/questions/tagged/material-ui).
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/blog/lab-tree-view-to-mui-x.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Migrate to the new package to start building with our powerful Tree
date: 2023-08-21T00:00:00.000Z
authors: ['flaviendelangle']
tags: ['MUI X', 'News']
card: true
card: false
---

After more than 4 years in the lab, the [Tree View](https://mui.com/x/react-tree-view/) components have found a new home as part of MUI X.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/experiments/blog/blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Blog post title
description: Our internationally distributed startup gathered on a remote island to get to know each other better. Here's what happened!
date: 2022-07-28T00:00:00.000Z
authors: ['samuelsycamore']
card: true
card: false
tags: ['Company']
---

Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/src/modules/components/TopLayoutBlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function TopLayoutBlog(props) {
const { description, rendered, title, headers } = docs.en;
const finalTitle = title || headers.title;
const router = useRouter();
const slug = router.pathname.replace(/\/blog\//, '');
const slug = router.pathname.replace(/(.*)\/(.*)/, '$2');
const { canonicalAsServer } = pathnameToLanguage(router.asPath);
const card =
headers.card === 'true'
Expand Down
18 changes: 18 additions & 0 deletions packages/markdown/parseMarkdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { marked } = require('marked');
const fs = require('fs');
const path = require('path');
const kebabCase = require('lodash/kebabCase');
const textToHash = require('./textToHash');
const prism = require('./prism');
Expand Down Expand Up @@ -675,6 +677,22 @@ ${headers.hooks
};
});

if (docs.en.headers.card === 'true') {
const slug = docs.en.location.replace(/(.*)\/(.*)\.md/, '$2');
const exists = fs.existsSync(
path.resolve(__dirname, `../../docs/public/static/blog/${slug}/card.png`),
);

if (!exists) {
throw new Error(
[
`MUI: the card image for the blog post "${slug}" is missing.`,
`Add a docs/public/static/blog/${slug}/card.png file then restart Next.js or remove card: true from the headers.`,
].join('\n'),
);
}
}

return { demos, docs };
}

Expand Down

0 comments on commit fe0d99d

Please sign in to comment.