Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: blog posts support /YYYY/MM/DD/blog-post/index.md pattern + blog frontmatter can reference relative images #5309

Merged
merged 5 commits into from
Aug 6, 2021

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Aug 6, 2021

Motivation

Blog posts generally have assets such as images.
It makes sense to create a folder for a blog post and co-locate all images related to the blog post in its folder.
Example: 2021-05-12-announcing-docusaurus-two-beta/index.md or 2021/05/12/announcing-docusaurus-two-beta/index.md
See also: #5301

This PR makes:

  • The default glob reading md files from subfolders
  • Ensure that we extract a decent blog post date from the relative file path (including folders)
  • Ensure that we can use relative images in Markdown frontmatter.

The following will now be supported and paths will be converted to Webpack file-loader require calls:

---
title: Announcing Docusaurus 2 Beta
authorImageURL: ./img/author.jpeg
image: ./img/social-card.png
---

Also:

  • refactor a bit blog post-processing logic (no behavior change)
  • content plugin guide docs linking to API reference doc
  • generic mdx-loader system to convert frontmatter relative paths to require calls, and expose a frontMatterAssets export

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

tests + dogfooding on our own blog

Blog posts keep the same URL:

Social card + author img keeps working

The little blog page size increase is expected: it's the url-loader inlining a small image as base64 in the HTML file

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Aug 6, 2021
@slorber slorber requested a review from lex111 as a code owner August 6, 2021 10:34
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Aug 6, 2021
@netlify
Copy link

netlify bot commented Aug 6, 2021

✔️ [V2]

🔨 Explore the source changes: 031c2ef

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/610d533fe5a91a000810e4af

😎 Browse the preview: https://deploy-preview-5309--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Aug 6, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 78
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-5309--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Aug 6, 2021

Size Change: +5.33 kB (+1%)

Total Size: 792 kB

Filename Size Change
website/build/blog/index.html 33.1 kB +5.32 kB (+19%) ⚠️
ℹ️ View Unchanged
Filename Size Change
website/.docusaurus/globalData.json 36.1 kB 0 B
website/build/assets/css/styles.********.css 93.2 kB 0 B
website/build/assets/js/main.********.js 403 kB +10 B (0%)
website/build/blog/2017/12/14/introducing-docusaurus/index.html 63.9 kB 0 B
website/build/docs/index.html 41.9 kB -1 B (0%)
website/build/docs/installation/index.html 49.6 kB -1 B (0%)
website/build/index.html 28.7 kB 0 B
website/build/tests/docs/index.html 22.6 kB 0 B
website/build/tests/docs/standalone/index.html 20.5 kB 0 B

compressed-size-action

@slorber slorber changed the title feat: blog post folders feat: blog posts supporting /YYYY/MM/DD/blog-post/index.md and similar date patterns Aug 6, 2021
…sets, converted to Webpack require calls and exposed as frontMatterAssets
@slorber slorber changed the title feat: blog posts supporting /YYYY/MM/DD/blog-post/index.md and similar date patterns feat: blog posts support /YYYY/MM/DD/blog-post/index.md pattern + blog frontmatter can reference relative images Aug 6, 2021
@slorber slorber merged commit cabb768 into master Aug 6, 2021
@slorber slorber deleted the slorber/blog-post-folders branch August 6, 2021 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants