From 4926d7392565bac8a925bc160cc53c8889eed2cd Mon Sep 17 00:00:00 2001 From: prototypa Date: Sun, 11 Sep 2022 12:51:42 -0400 Subject: [PATCH] Update Blog configuration --- README.md | 32 ++++++++++++++++++----------- src/config.mjs | 17 ++++++++++----- src/pages/[...blog]/[...page].astro | 5 +++-- src/pages/[...blog]/[slug].astro | 6 +++--- src/utils/permalinks.js | 9 ++++---- 5 files changed, 43 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index a44a5e0..6fc7252 100644 --- a/README.md +++ b/README.md @@ -142,23 +142,31 @@ export const SITE = { }; export const BLOG = { - disabled: false, - slug: "blog", // you can change this to "articles" (/articles) + disabled: false, + postsPerPage: 4, - postsWithoutBlogSlug: true, // true (/some-slug), false (/blog/some-slug), - postsPerPage: 6, + blog: { + disabled: false, + pathname: 'blog', // blog main path, you can change this to "articles" (/articles) + }, - category: { - disabled: false, - slug: "category", // set empty to change from /category/some-slug to /some-slug - }, + post: { + disabled: false, + pathname: '', // empty for /some-post, value for /pathname/some-post + }, - tag: { - disabled: false, - slug: "tag", - }, + category: { + disabled: false, + pathname: 'category', // set empty to change from /category/some-category to /some-category + }, + + tag: { + disabled: false, + pathname: 'tag', // set empty to change from /tag/some-tag to /some-tag + }, }; + ```
diff --git a/src/config.mjs b/src/config.mjs index a219428..7d9852f 100644 --- a/src/config.mjs +++ b/src/config.mjs @@ -13,18 +13,25 @@ export const SITE = { export const BLOG = { disabled: false, - slug: 'blog', + postsPerPage: 4, - postsWithoutBlogSlug: true, - postsPerPage: 6, + blog: { + disabled: false, + pathname: 'blog', // blog main path, you can change this to "articles" (/articles) + }, + + post: { + disabled: false, + pathname: '', // empty for /some-post, value for /pathname/some-post + }, category: { disabled: false, - slug: 'category', // set empty to change from /category/some-slug to /some-slug + pathname: 'category', // set empty to change from /category/some-category to /some-category }, tag: { disabled: false, - slug: 'tag', + pathname: 'tag', // set empty to change from /tag/some-tag to /some-tag }, }; diff --git a/src/pages/[...blog]/[...page].astro b/src/pages/[...blog]/[...page].astro index 5944dcd..ba27ce6 100644 --- a/src/pages/[...blog]/[...page].astro +++ b/src/pages/[...blog]/[...page].astro @@ -9,7 +9,7 @@ import { fetchPosts } from '~/utils/posts'; import { getCanonical, getPermalink, BLOG_BASE } from '~/utils/permalinks'; export async function getStaticPaths({ paginate }) { - if (BLOG?.disabled) return []; + if (BLOG?.disabled || BLOG?.blog?.disabled) return []; const posts = await fetchPosts(); @@ -26,7 +26,8 @@ const meta = { title: `Blog ${currentPage > 1 ? `— Page ${currentPage} ` : ''}— ${SITE.name}`, description: SITE.description, canonical: getCanonical(getPermalink(page.url.current)), - ogType: "blog" + ogType: "blog", + noindex: currentPage > 1 }; --- diff --git a/src/pages/[...blog]/[slug].astro b/src/pages/[...blog]/[slug].astro index 1a03ee7..47175fa 100644 --- a/src/pages/[...blog]/[slug].astro +++ b/src/pages/[...blog]/[slug].astro @@ -4,19 +4,19 @@ import { SITE, BLOG } from '~/config.mjs'; import Layout from '~/layouts/PageLayout.astro'; import SinglePost from '~/components/blog/SinglePost.astro'; -import { getCanonical, getPermalink, cleanSlug, BLOG_BASE } from '~/utils/permalinks'; +import { getCanonical, getPermalink, cleanSlug, POST_BASE } from '~/utils/permalinks'; import { fetchPosts } from '~/utils/posts'; import { findImage } from '~/utils/images'; export async function getStaticPaths() { - if (BLOG?.disabled) return []; + if (BLOG?.disabled || BLOG?.post?.disabled) return []; const posts = await fetchPosts(); return posts.map((post) => ({ params: { slug: cleanSlug(post.slug), - blog: BLOG.postsWithoutBlogSlug ? undefined : BLOG_BASE || undefined, + blog: POST_BASE || undefined, }, props: { post }, })); diff --git a/src/utils/permalinks.js b/src/utils/permalinks.js index 170f438..6e6c075 100644 --- a/src/utils/permalinks.js +++ b/src/utils/permalinks.js @@ -17,9 +17,10 @@ const basePathname = trimSlash(SITE.basePathname); export const cleanSlug = (text) => slugify(trimSlash(text)); -export const BLOG_BASE = cleanSlug(BLOG.slug); -export const CATEGORY_BASE = cleanSlug(BLOG?.category?.slug); -export const TAG_BASE = cleanSlug(BLOG?.tag?.slug); +export const BLOG_BASE = cleanSlug(BLOG?.blog?.pathname); +export const POST_BASE = cleanSlug(BLOG?.post?.pathname); +export const CATEGORY_BASE = cleanSlug(BLOG?.category?.pathname); +export const TAG_BASE = cleanSlug(BLOG?.tag?.pathname); /** */ export const getCanonical = (path = '') => new URL(path, SITE.origin); @@ -36,7 +37,7 @@ export const getPermalink = (slug = '', type = 'page') => { return createPath(basePathname, TAG_BASE, _slug); case 'post': - return createPath(basePathname, BLOG.postsWithoutBlogSlug ? '' : BLOG_BASE, _slug); + return createPath(basePathname, POST_BASE, _slug); case 'page': default: