Skip to content

Commit 4153184

Browse files
authored
feat: Add custom blog plugin (#291)
* Remove twitter * Add custom blog plugin that automatically displays the latest blog post on the index page
1 parent 9edb883 commit 4153184

16 files changed

+87
-50
lines changed

content/news/2020-04-24-jsonforms-2-4-0-alpha3.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-2-4-0-alpha3
33
title: JSON Forms v2.4.0-alpha.3
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2020-05-25-jsonforms-2-4-0-beta0.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-2-4-0-beta0
33
title: JSON Forms v2.4.0-beta.0
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2020-06-23-jsonforms-2-4-0.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-2-4-0
33
title: JSON Forms v2.4.0
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2020-08-21-jsonforms-2-4-1-beta0.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-2-4-1-beta0
33
title: JSON Forms v2.4.1-beta.0
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2020-09-30-jsonforms-2-4-1.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-2-4-1
33
title: JSON Forms v2.4.1
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2020-12-03-jsonforms-2-5-alpha1.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-2-5-alpha1
33
title: JSON Forms v2.5-alpha.1
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2021-01-26-jsonforms-2-5.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-2-5
33
title: JSON Forms v2.5
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2021-03-11-jsonforms-2.5.1-alpha1.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-2-5-1-alpha1
33
title: JSON Forms v2.5.1-alpha.1
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2021-05-20-jsonforms-2.5.1.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-2-5-1
33
title: JSON Forms v2.5.1
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2021-06-29-smaller-and-faster-jsonforms.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: smaller-and-faster-jsonforms
33
title: Smaller and faster JSON Forms
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2021-07-08-move-to-discourse.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: move-to-discourse
33
title: Moving to Discourse
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97

content/news/2021-12-22-jsonforms-3-0-0-beta0.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-3-0-0-beta0
33
title: JSON Forms 3.0.0-beta0
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97
We've got an early present for you 🎁! Today we merged the last feature for JSON Forms 3.0 and released the first beta version v3.0.0-beta.0 🎉 Try our new ESM module builds today!

content/news/2022-07-25-jsonforms-3-0-0-rc0.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
slug: jsonforms-3-0-0-rc0
33
title: JSON Forms 3.0.0-rc0
44
author: JSON Forms
5-
author_title: Twitter
6-
author_url: https://twitter.com/jsonforms
75
author_image_url: /img/logo.svg
86
---
97
Great news! We are in the final stretches of the long awaited JSON Forms 3.0 release. Today we published the release candidate "3.0.0-rc.0" 🎉

docusaurus.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ module.exports = {
9292
{
9393
title: 'More',
9494
items: [
95-
{
96-
label: 'Twitter',
97-
href: 'https://twitter.com/JSONForms',
98-
},
9995
{
10096
label: 'EclipseSource Blog',
10197
href: 'https://eclipsesource.com/blogs/tag/jsonforms',
@@ -180,7 +176,7 @@ module.exports = {
180176
},
181177
],
182178
[
183-
'@docusaurus/plugin-content-blog',
179+
'./plugins/custom-blog-plugin',
184180
{
185181
id: 'news',
186182
path: 'content/news',

plugins/custom-blog-plugin.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Source: https://github.com/facebook/docusaurus/issues/4138#issuecomment-1703083513
2+
3+
const blogPluginExports = require('@docusaurus/plugin-content-blog');
4+
5+
const defaultBlogPlugin = blogPluginExports.default;
6+
7+
async function blogPluginExtended(...pluginArgs) {
8+
const blogPluginInstance = await defaultBlogPlugin(...pluginArgs);
9+
10+
const pluginOptions = pluginArgs[1];
11+
12+
return {
13+
// Add all properties of the default blog plugin so existing functionality is preserved
14+
...blogPluginInstance,
15+
/**
16+
* Override the default `contentLoaded` hook to access blog posts data
17+
*/
18+
contentLoaded: async function (params) {
19+
const { content, actions } = params;
20+
21+
// Get the latest blog posts
22+
const recentPostsLimit = 1;
23+
const recentPosts = [...content.blogPosts].splice(0, recentPostsLimit);
24+
25+
async function createRecentPostModule(blogPost, index) {
26+
return {
27+
// Inject the metadata you need for each recent blog post
28+
metadata: await actions.createData(
29+
`home-page-recent-post-metadata-${index}.json`,
30+
JSON.stringify(blogPost.metadata)
31+
),
32+
33+
// Inject the MDX excerpt as a JSX component prop
34+
// (what's above the <!-- truncate --> marker)
35+
BlogPost: {
36+
__import: true,
37+
// The markdown file for the blog post will be loaded by webpack
38+
path: blogPost.metadata.source,
39+
query: {
40+
truncated: true,
41+
},
42+
},
43+
};
44+
}
45+
46+
actions.addRoute({
47+
// Add route for the home page
48+
path: '/',
49+
exact: true,
50+
51+
// The component to use for the "Home" page route
52+
component: '@site/src/components/home/index.js',
53+
54+
// These are the props that will be passed to our "Home" page component
55+
modules: {
56+
recentPosts: await Promise.all(
57+
recentPosts.map(createRecentPostModule)
58+
),
59+
},
60+
});
61+
62+
// Call the default overridden `contentLoaded` implementation
63+
return blogPluginInstance.contentLoaded(params);
64+
},
65+
};
66+
}
67+
68+
module.exports = {
69+
...blogPluginExports,
70+
default: blogPluginExtended,
71+
};

content/pages/index.js renamed to src/components/home/index.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ import Layout from '@theme/Layout';
44
import Link from '@docusaurus/Link';
55
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
66
import useBaseUrl from '@docusaurus/useBaseUrl';
7-
import styles from './assets/index.module.css';
7+
import styles from '../../../content/pages/assets/index.module.css';
88
import corePackageJson from '@jsonforms/core/package';
99

10-
import SchemaIcon from '../../static/img/schemaIcon.svg';
10+
import SchemaIcon from '../../../static/img/schemaIcon.svg';
1111
import FeaturesIcon from '@mui/icons-material/Report';
1212
import CustomizeIcon from '@mui/icons-material/Brush';
13-
import ArchitectureSmall from '../../static/img/architecture_small.svg';
14-
import AngularLogo from '../../static/img/angular-logo.svg';
15-
import ReactLogo from '../../static/img/react-logo.svg';
16-
import VueLogo from '../../static/img/vue-logo.svg';
13+
import ArchitectureSmall from '../../../static/img/architecture_small.svg';
14+
import AngularLogo from '../../../static/img/angular-logo.svg';
15+
import ReactLogo from '../../../static/img/react-logo.svg';
16+
import VueLogo from '../../../static/img/vue-logo.svg';
1717

1818
import Card from '@mui/material/Card';
1919
import CardContent from '@mui/material/CardContent';
2020
import Button from '@mui/material/Button';
2121

22-
import { Demo } from '../../src/components/common/Demo';
23-
import schema from './assets/schema.json';
24-
import uischema from './assets/uischema.json';
22+
import { Demo } from '../common/Demo';
23+
import schema from '../../../content/pages/assets/schema.json';
24+
import uischema from '../../../content/pages/assets/uischema.json';
2525

2626
const currentVersion = process.env.CURRENTVERSION ?? corePackageJson.version;
2727
const nextVersion = process.env.NEXTVERSION;
@@ -32,9 +32,12 @@ const nextVersionText =
3232

3333
const data = { firstName: 'Max', lastName: 'Power' };
3434

35-
function Home() {
35+
function Home({ recentPosts }) {
3636
const context = useDocusaurusContext();
3737
const {siteConfig = {}} = context;
38+
const recentPost = recentPosts[0];
39+
const { BlogPost } = recentPost;
40+
3841
return (
3942
<Layout
4043
title={siteConfig.tagline}
@@ -107,15 +110,8 @@ function Home() {
107110
<section className={styles.sectionNews}>
108111
<Card className={styles.newsCard}>
109112
<CardContent>
110-
We released v3.2.0 🎉. Besides various fixes and improved developer tooling, this release adds middleware support to all bindings. This makes it a breeze to hook into data updates!
111-
<br/>
112-
With this release, the Angular bindings and Angular Material renderer set now support Angular 16 and 17. Special thanks to <a href="https://github.com/JBBianchi">JBBianchi</a> for contributing this massive upgrade.
113-
<br />
114-
You can find the full changelog in the <a href="https://github.com/eclipsesource/jsonforms/releases/tag/v3.2.0">Github release</a>.
115-
<br />
116-
We welcome any feedback of curious users. Any questions? Check out our <a href="http://jsonforms.discourse.group">community forum</a>. See also our <a href="https://github.com/eclipsesource/jsonforms/blob/master/MIGRATION.md">migration guide</a>.
117-
<br/>
118-
<span style={{ display: 'block', textAlign: 'right', width: '100%'}}>24th January 2024</span>
113+
<BlogPost />
114+
<span style={{ display: 'block', textAlign: 'right', width: '100%'}}>{recentPost.metadata.formattedDate}</span>
119115
</CardContent>
120116
</Card>
121117
<Link to='/news' className={styles.newsButton}>

0 commit comments

Comments
 (0)