Skip to content

Commit

Permalink
add pageBasePath to blog
Browse files Browse the repository at this point in the history
  • Loading branch information
ilg-ul committed Jan 25, 2024
1 parent 83e5293 commit be48705
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ export function paginateBlogPosts({
blogTitle,
blogDescription,
postsPerPageOption,
pageBasePath,
}: {
blogPosts: BlogPost[];
basePageUrl: string;
blogTitle: string;
blogDescription: string;
postsPerPageOption: number | 'ALL';
pageBasePath: string;
}): BlogPaginated[] {
const totalCount = blogPosts.length;
const postsPerPage =
Expand All @@ -81,7 +83,7 @@ export function paginateBlogPosts({

function permalink(page: number) {
return page > 0
? normalizeUrl([basePageUrl, `page/${page + 1}`])
? normalizeUrl([basePageUrl, `${pageBasePath}/${page + 1}`])
: basePageUrl;
}

Expand Down Expand Up @@ -119,6 +121,7 @@ export function getBlogTags({
blogTitle: string;
blogDescription: string;
postsPerPageOption: number | 'ALL';
pageBasePath: string;
}): BlogTags {
const groups = groupTaggedItems(
blogPosts,
Expand Down
3 changes: 3 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export default async function pluginContentBlog(
blogDescription,
blogTitle,
blogSidebarTitle,
pageBasePath,
} = options;

const baseBlogUrl = normalizeUrl([baseUrl, routeBasePath]);
Expand Down Expand Up @@ -159,13 +160,15 @@ export default async function pluginContentBlog(
blogDescription,
postsPerPageOption,
basePageUrl: baseBlogUrl,
pageBasePath,
});

const blogTags: BlogTags = getBlogTags({
blogPosts,
postsPerPageOption,
blogDescription,
blogTitle,
pageBasePath,
});

return {
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
routeBasePath: 'blog',
tagsBasePath: 'tags',
archiveBasePath: 'archive',
pageBasePath: 'page',
path: 'blog',
editLocalizedFiles: false,
authorsMapPath: 'authors.yml',
Expand All @@ -61,6 +62,7 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
.allow(null),
routeBasePath: RouteBasePathSchema.default(DEFAULT_OPTIONS.routeBasePath),
tagsBasePath: Joi.string().default(DEFAULT_OPTIONS.tagsBasePath),
pageBasePath: Joi.string().default(DEFAULT_OPTIONS.pageBasePath),
include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
postsPerPage: Joi.alternatives()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the
* `routeBasePath`. **DO NOT** include a trailing slash.
*/
tagsBasePath: string;
/**
* URL route for the pages section of your blog. Will be appended to
* `routeBasePath`. **DO NOT** include a trailing slash.
*/
pageBasePath: string;
/**
* URL route for the archive section of your blog. Will be appended to
* `routeBasePath`. **DO NOT** include a trailing slash. Use `null` to
Expand Down

0 comments on commit be48705

Please sign in to comment.