mirror of
https://gitea.com/gitea/blog.git
synced 2024-06-02 04:11:23 +05:30
use customized blog plugin
This commit is contained in:
parent
6e1d4615e5
commit
7ac27f1df7
|
@ -18,25 +18,32 @@ const config = {
|
|||
defaultLocale: 'en',
|
||||
locales: ['en'],
|
||||
},
|
||||
|
||||
plugins: [
|
||||
[
|
||||
require.resolve('./plugins/blog'),
|
||||
{
|
||||
showReadingTime: true,
|
||||
routeBasePath: '/',
|
||||
editUrl: 'https://gitea.com/gitea/blog/src/branch/main/',
|
||||
blogSidebarTitle: 'All posts',
|
||||
blogSidebarCount: 'ALL',
|
||||
postsPerPage: 10,
|
||||
path: 'content/post',
|
||||
blogTagsPostsComponent: require.resolve(
|
||||
"./src/theme/BlogListPage/index.js",
|
||||
),
|
||||
},
|
||||
]
|
||||
],
|
||||
presets: [
|
||||
[
|
||||
'classic',
|
||||
/** @type {import('@docusaurus/preset-classic').Options} */
|
||||
({
|
||||
docs: false,
|
||||
blog: {
|
||||
showReadingTime: true,
|
||||
routeBasePath: '/',
|
||||
editUrl: 'https://gitea.com/gitea/blog/src/branch/main/',
|
||||
blogSidebarTitle: 'All posts',
|
||||
blogSidebarCount: 'ALL',
|
||||
postsPerPage: 10,
|
||||
path: 'content/post',
|
||||
blogTagsPostsComponent: require.resolve(
|
||||
"./src/theme/BlogListPage/index.js",
|
||||
),
|
||||
},
|
||||
// blog is enabled through a custom plugin, so we disable it from preset
|
||||
// ./plugins/blog/index.js
|
||||
blog: false,
|
||||
theme: {
|
||||
customCss: require.resolve('./src/css/custom.css'),
|
||||
},
|
||||
|
|
27
plugins/blog/index.js
Normal file
27
plugins/blog/index.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
const blogPluginExports = require('@docusaurus/plugin-content-blog');
|
||||
|
||||
const blogPlugin = blogPluginExports.default;
|
||||
|
||||
/*
|
||||
* This plugin enhances the default '@docusaurus/plugin-content-blog' plugin with `tags` added to `globalData`.
|
||||
* `tags` are later consumed in `src/theme/BlogListPage`.
|
||||
*/
|
||||
async function blogPluginEnhanced(context, options) {
|
||||
const blogPluginInstance = await blogPlugin(context, options);
|
||||
return {
|
||||
...blogPluginInstance,
|
||||
|
||||
async contentLoaded(...contentLoadedArgs) {
|
||||
await blogPluginInstance.contentLoaded(...contentLoadedArgs);
|
||||
const { actions, content } = contentLoadedArgs[0];
|
||||
const { setGlobalData } = actions;
|
||||
const { blogTags } = content;
|
||||
setGlobalData({tags: blogTags});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
...blogPluginExports,
|
||||
default: blogPluginEnhanced
|
||||
};
|
16
plugins/repo/index.js
Normal file
16
plugins/repo/index.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
module.exports = () => ({
|
||||
name: "docusaurus-repo-plugin",
|
||||
async loadContent() {
|
||||
const response = await fetch(
|
||||
`https://github-api.questdb.io/github/repo`,
|
||||
)
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
return data
|
||||
},
|
||||
async contentLoaded({ content, actions }) {
|
||||
const { setGlobalData } = actions
|
||||
setGlobalData({ repo: content })
|
||||
},
|
||||
})
|
|
@ -15,8 +15,8 @@ import SearchMetadata from '@theme/SearchMetadata';
|
|||
// import BlogPostItems from '@theme/BlogPostItems';
|
||||
import { ListItem } from './ListItem';
|
||||
import { Chips } from './Chips';
|
||||
import { tagNames } from '@site/tagNames.js';
|
||||
import styles from './styles.module.css';
|
||||
import useGlobalData from '@docusaurus/useGlobalData';
|
||||
|
||||
function BlogListPageMetadata(props) {
|
||||
const isTagsPage = props.tag !== undefined;
|
||||
|
@ -37,6 +37,12 @@ function BlogListPageMetadata(props) {
|
|||
function BlogListPageContent(props) {
|
||||
const isTagsPage = props.tag !== undefined;
|
||||
const metadata = isTagsPage ? props.listMetadata: props.metadata;
|
||||
const globalData = useGlobalData();
|
||||
const myPluginData = globalData['docusaurus-plugin-content-blog']['default'];
|
||||
const tagNames = [];
|
||||
for (const tag of Object.keys(myPluginData.tags)) {
|
||||
tagNames.push(myPluginData.tags[tag].label);
|
||||
}
|
||||
const {items, sidebar} = props;
|
||||
// No official way to get all tags right now: https://github.com/facebook/docusaurus/discussions/5856
|
||||
// unless show all posts without pagination, so added all tag list link
|
||||
|
|
19
tagNames.js
19
tagNames.js
|
@ -1,19 +0,0 @@
|
|||
export const tagNames = [
|
||||
'actions',
|
||||
'announcement',
|
||||
'backporter',
|
||||
'deployment',
|
||||
'docs',
|
||||
'feature',
|
||||
'gitea',
|
||||
'helm-chart',
|
||||
'jupyter',
|
||||
'label',
|
||||
'project',
|
||||
'quarterly',
|
||||
'release',
|
||||
'rendering',
|
||||
'tea',
|
||||
'tutorial',
|
||||
'ui'
|
||||
]
|
Loading…
Reference in a new issue