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

[website] Add a Blog index page #30121

Merged
merged 35 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c8acd40
initial prototype commit
danilo-leal Dec 8, 2021
b4685c4
add blog link to header
siriwatknp Dec 15, 2021
acbb270
add first iteration of blog index
siriwatknp Dec 15, 2021
dd306d5
remove experiment
siriwatknp Dec 15, 2021
7c6f930
fix types
siriwatknp Dec 15, 2021
7fbdc05
design adjustments
danilo-leal Dec 17, 2021
0675a90
sourcing tags and add pagination
siriwatknp Dec 18, 2021
73f3ff5
update blog tags
siriwatknp Dec 18, 2021
6d2e686
use delete icon on Chip
siriwatknp Dec 18, 2021
d59995e
fix a11y
siriwatknp Dec 21, 2021
e4aa2a4
fix semantic
siriwatknp Dec 21, 2021
febca62
Merge branch 'master' of https://github.com/mui-org/material-ui into …
siriwatknp Dec 21, 2021
bae0577
add feature toggle and fix broken avatar
siriwatknp Dec 21, 2021
20e56b9
update feature toggle to commonjs
siriwatknp Dec 25, 2021
c7c994a
Merge branch 'master' of https://github.com/mui-org/material-ui into …
danilo-leal Jan 3, 2022
e866e06
a few design tweaks, pagination theming and post preview clickable area
danilo-leal Jan 3, 2022
108e6b4
Merge branch 'master' into blog-index-page
siriwatknp Jan 6, 2022
b4b2d6b
remove hover from chip in post preview
danilo-leal Jan 6, 2022
0f090ad
update posts tags
danilo-leal Jan 6, 2022
f42cdd0
top layout blog update and tweaks to the index page
danilo-leal Jan 6, 2022
0c78961
small fine tunings
danilo-leal Jan 6, 2022
7f4bddc
fix author names
siriwatknp Jan 7, 2022
068585d
fix tag count
siriwatknp Jan 7, 2022
ed19aee
few tweaks
danilo-leal Jan 7, 2022
6d9eac0
Merge branch 'master' into blog-index-page
danilo-leal Jan 7, 2022
0731b23
remove tag count
siriwatknp Jan 11, 2022
17f3389
Merge branch 'master' of https://github.com/mui-org/material-ui into …
siriwatknp Jan 11, 2022
eda146f
Merge branch 'blog-index-page' of https://github.com/danilo-leal/mate…
siriwatknp Jan 11, 2022
d200ced
fix feature toggle
siriwatknp Jan 11, 2022
69b56a9
small tweak to the chip color
danilo-leal Jan 11, 2022
a442ea4
small tweak to the blog post design
danilo-leal Jan 11, 2022
578d5ea
change to ref
siriwatknp Jan 12, 2022
f10ec63
fix on button's padding
danilo-leal Jan 12, 2022
38dd3f0
copy update
danilo-leal Jan 12, 2022
481fe14
use author name as alt text for avatar picture
danilo-leal Jan 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/lib/sourcing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import fs from 'fs';
import path from 'path';
import { getHeaders } from '@mui/markdown';

const blogDir = path.join(process.cwd(), 'pages/blog');

export const getBlogFilePaths = (ext = '.md') => {
return fs.readdirSync(blogDir).filter((file) => file.endsWith(ext));
};

export interface BlogPost {
slug: string;
title: string;
description: string;
image?: string;
tags?: Array<string>;
authors?: Array<string>;
date?: string;
}

export const getBlogPost = (filePath: string): BlogPost => {
const slug = filePath.replace(/\.md$/, '');
const content = fs.readFileSync(path.join(blogDir, filePath), 'utf-8');

const headers = getHeaders(content) as unknown as BlogPost;

return {
...headers,
slug,
};
};

export const getAllBlogPosts = () => {
const filePaths = getBlogFilePaths();
const rawBlogPosts = filePaths
.map((name) => getBlogPost(name))
// sort allBlogPosts by date in descending order
.sort((post1, post2) => {
if (post1.date && post2.date) {
return new Date(post1.date) > new Date(post2.date) ? -1 : 1;
}
if (post1.date && !post2.date) {
return 1;
}
return -1;
});
const allBlogPosts = rawBlogPosts.filter((post) => !!post.title);
const tagInfo: Record<string, number | undefined> = {};
allBlogPosts.forEach((post) => {
(post.tags || []).forEach((tag) => {
tagInfo[tag] = (tagInfo[tag] || 0) + 1;
});
});
return {
rawBlogPosts, // all posts from the directory
allBlogPosts, // posts with at least a title
allTags: Object.keys(tagInfo),
tagInfo,
};
};
3 changes: 3 additions & 0 deletions docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ module.exports = {
if (process.env.PULL_REQUEST !== 'true' && page.pathname.startsWith('/experiments')) {
return;
}
if (!FEATURE_TOGGLE.enable_blog_index && page.pathname === '/blog') {
return;
}
if (!page.children) {
// map api-docs to api
// i: /api-docs/* > /api/* (old structure)
Expand Down
Loading