Add support for new config.yaml
This commit is contained in:
@ -1,23 +1,13 @@
|
||||
---
|
||||
import { SITE, BLOG } from '~/config.mjs';
|
||||
|
||||
import Layout from '~/layouts/PageLayout.astro';
|
||||
import BlogList from '~/components/blog/List.astro';
|
||||
import Headline from '~/components/blog/Headline.astro';
|
||||
import Pagination from '~/components/blog/Pagination.astro';
|
||||
// import PostTags from "~/components/blog/Tags.astro";
|
||||
|
||||
import { fetchPosts } from '~/utils/blog';
|
||||
// import { findTags, findCategories } from '~/utils/blog';
|
||||
import { BLOG_BASE } from '~/utils/permalinks';
|
||||
import { blogListRobots, getStaticPathsBlogList } from '~/utils/blog';
|
||||
|
||||
export async function getStaticPaths({ paginate }) {
|
||||
if (BLOG?.disabled || BLOG?.list?.disabled) return [];
|
||||
return paginate(await fetchPosts(), {
|
||||
params: { blog: BLOG_BASE || undefined },
|
||||
pageSize: BLOG.postsPerPage,
|
||||
});
|
||||
}
|
||||
export const getStaticPaths = getStaticPathsBlogList();
|
||||
|
||||
const { page } = Astro.props;
|
||||
const currentPage = page.currentPage ?? 1;
|
||||
@ -25,15 +15,19 @@ const currentPage = page.currentPage ?? 1;
|
||||
// const allCategories = await findCategories();
|
||||
// const allTags = await findTags();
|
||||
|
||||
const meta = {
|
||||
const metadata = {
|
||||
title: `Blog${currentPage > 1 ? ` — Page ${currentPage}` : ''}`,
|
||||
description: SITE.description,
|
||||
noindex: BLOG?.list?.noindex || currentPage > 1,
|
||||
ogType: 'blog',
|
||||
robots: {
|
||||
index: blogListRobots?.index && currentPage === 1,
|
||||
follow: blogListRobots?.follow,
|
||||
},
|
||||
openGraph: {
|
||||
type: 'blog',
|
||||
},
|
||||
};
|
||||
---
|
||||
|
||||
<Layout {meta}>
|
||||
<Layout metadata={metadata}>
|
||||
<section class="px-6 sm:px-6 py-12 sm:py-16 lg:py-20 mx-auto max-w-4xl">
|
||||
<Headline
|
||||
subtitle="A statically generated blog example with news, tutorials, resources and other interesting content related to AstroWind"
|
||||
|
@ -1,47 +1,28 @@
|
||||
---
|
||||
import { SITE, BLOG } from '~/config.mjs';
|
||||
import { blogCategoryRobots, getStaticPathsBlogCategory } from '~/utils/blog';
|
||||
|
||||
import Layout from '~/layouts/PageLayout.astro';
|
||||
import BlogList from '~/components/blog/List.astro';
|
||||
import Headline from '~/components/blog/Headline.astro';
|
||||
import Pagination from '~/components/blog/Pagination.astro';
|
||||
|
||||
import { fetchPosts } from '~/utils/blog';
|
||||
import { CATEGORY_BASE } from '~/utils/permalinks';
|
||||
|
||||
export async function getStaticPaths({ paginate }) {
|
||||
if (BLOG?.disabled || BLOG?.category?.disabled) return [];
|
||||
|
||||
const posts = await fetchPosts();
|
||||
const categories = new Set();
|
||||
posts.map((post) => {
|
||||
typeof post.category === 'string' && categories.add(post.category.toLowerCase());
|
||||
});
|
||||
|
||||
return Array.from(categories).map((category: string) =>
|
||||
paginate(
|
||||
posts.filter((post) => typeof post.category === 'string' && category === post.category.toLowerCase()),
|
||||
{
|
||||
params: { category: category, blog: CATEGORY_BASE || undefined },
|
||||
pageSize: BLOG.postsPerPage,
|
||||
props: { category },
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
export const getStaticPaths = getStaticPathsBlogCategory();
|
||||
|
||||
const { page, category } = Astro.props;
|
||||
|
||||
const currentPage = page.currentPage ?? 1;
|
||||
const meta = {
|
||||
title: `Category'${category}' ${currentPage > 1 ? ` — Page ${currentPage}` : ''}`,
|
||||
description: SITE.description,
|
||||
noindex: BLOG?.category?.noindex,
|
||||
|
||||
const metadata = {
|
||||
title: `Category '${category}' ${currentPage > 1 ? ` — Page ${currentPage}` : ''}`,
|
||||
robots: {
|
||||
index: blogCategoryRobots?.index,
|
||||
follow: blogCategoryRobots?.follow,
|
||||
},
|
||||
};
|
||||
---
|
||||
|
||||
<Layout meta={meta}>
|
||||
<section class="px-6 sm:px-6 py-12 sm:py-16 lg:py-20 mx-auto max-w-4xl">
|
||||
<Layout metadata={metadata}>
|
||||
<section class="px-4 md:px-6 py-12 sm:py-16 lg:py-20 mx-auto max-w-4xl">
|
||||
<Headline><span class="capitalize">{category.replaceAll('-', ' ')}</span></Headline>
|
||||
<BlogList posts={page.data} />
|
||||
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
||||
|
@ -1,47 +1,28 @@
|
||||
---
|
||||
import { SITE, BLOG } from '~/config.mjs';
|
||||
import { blogTagRobots, getStaticPathsBlogTag } from '~/utils/blog';
|
||||
|
||||
import Layout from '~/layouts/PageLayout.astro';
|
||||
import BlogList from '~/components/blog/List.astro';
|
||||
import Headline from '~/components/blog/Headline.astro';
|
||||
import Pagination from '~/components/blog/Pagination.astro';
|
||||
|
||||
import { fetchPosts } from '~/utils/blog';
|
||||
import { TAG_BASE } from '~/utils/permalinks';
|
||||
import Headline from '~/components/blog/Headline.astro';
|
||||
|
||||
export async function getStaticPaths({ paginate }) {
|
||||
if (BLOG?.disabled || BLOG?.tag?.disabled) return [];
|
||||
|
||||
const posts = await fetchPosts();
|
||||
const tags = new Set();
|
||||
posts.map((post) => {
|
||||
Array.isArray(post.tags) && post.tags.map((tag) => tags.add(tag.toLowerCase()));
|
||||
});
|
||||
|
||||
return Array.from(tags).map((tag: string) =>
|
||||
paginate(
|
||||
posts.filter((post) => Array.isArray(post.tags) && post.tags.find((elem) => elem.toLowerCase() === tag)),
|
||||
{
|
||||
params: { tag: tag, blog: TAG_BASE || undefined },
|
||||
pageSize: BLOG.postsPerPage,
|
||||
props: { tag },
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
export const getStaticPaths = getStaticPathsBlogTag();
|
||||
|
||||
const { page, tag } = Astro.props;
|
||||
|
||||
const currentPage = page.currentPage ?? 1;
|
||||
const meta = {
|
||||
|
||||
const metadata = {
|
||||
title: `Posts by tag '${tag}'${currentPage > 1 ? ` — Page ${currentPage} ` : ''}`,
|
||||
description: SITE.description,
|
||||
noindex: BLOG?.tag?.noindex,
|
||||
robots: {
|
||||
index: blogTagRobots?.index,
|
||||
follow: blogTagRobots?.follow,
|
||||
},
|
||||
};
|
||||
---
|
||||
|
||||
<Layout meta={meta}>
|
||||
<section class="px-6 sm:px-6 py-12 sm:py-16 lg:py-20 mx-auto max-w-4xl">
|
||||
<Layout metadata={metadata}>
|
||||
<section class="px-4 md:px-6 py-12 sm:py-16 lg:py-20 mx-auto max-w-4xl">
|
||||
<Headline>Tag: {tag}</Headline>
|
||||
<BlogList posts={page.data} />
|
||||
<Pagination prevUrl={page.url.prev} nextUrl={page.url.next} />
|
||||
|
@ -1,38 +1,39 @@
|
||||
---
|
||||
import { BLOG } from '~/config.mjs';
|
||||
|
||||
import merge from 'lodash.merge';
|
||||
import type { ImageMetadata } from 'astro';
|
||||
import Layout from '~/layouts/PageLayout.astro';
|
||||
import SinglePost from '~/components/blog/SinglePost.astro';
|
||||
import ToBlogLink from '~/components/blog/ToBlogLink.astro';
|
||||
|
||||
import { getCanonical, getPermalink } from '~/utils/permalinks';
|
||||
import { fetchPosts } from '~/utils/blog';
|
||||
import { getStaticPathsBlogPost, blogPostRobots } from '~/utils/blog';
|
||||
import { findImage } from '~/utils/images';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
if (BLOG?.disabled || BLOG?.post?.disabled) return [];
|
||||
return (await fetchPosts()).map((post) => ({
|
||||
params: {
|
||||
blog: post.permalink,
|
||||
},
|
||||
props: { post },
|
||||
}));
|
||||
}
|
||||
export const getStaticPaths = getStaticPathsBlogPost();
|
||||
|
||||
const { post } = Astro.props;
|
||||
const url = getCanonical(getPermalink(post.permalink, 'post'));
|
||||
|
||||
const meta = {
|
||||
title: post.title,
|
||||
description: post.description,
|
||||
canonical: post.canonical || url,
|
||||
image: await findImage(post.image),
|
||||
noindex: BLOG?.post?.noindex,
|
||||
ogType: 'article',
|
||||
};
|
||||
const url = getCanonical(getPermalink(post.permalink, 'post'));
|
||||
const image = (await findImage(post.image)) as ImageMetadata | undefined;
|
||||
|
||||
const metadata = merge(
|
||||
{
|
||||
title: post.title,
|
||||
description: post.excerpt,
|
||||
robots: {
|
||||
index: blogPostRobots?.index,
|
||||
follow: blogPostRobots?.follow,
|
||||
},
|
||||
openGraph: {
|
||||
type: 'article',
|
||||
...(image ? { images: [{ url: image?.src, width: image?.width, height: image?.height }] } : {}),
|
||||
},
|
||||
},
|
||||
{ ...(post?.metadata ? { ...post.metadata, canonical: post.metadata?.canonical || url } : {}) }
|
||||
);
|
||||
---
|
||||
|
||||
<Layout {meta}>
|
||||
<SinglePost post={{ ...post, image: meta.image }} url={url} />
|
||||
<Layout metadata={metadata}>
|
||||
<SinglePost post={{ ...post, image: image }} url={url} />
|
||||
<ToBlogLink />
|
||||
</Layout>
|
||||
|
Reference in New Issue
Block a user