mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-18 14:13:30 +09:00
added contentParser with type support
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
---
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
import PageHeader from "@/partials/PageHeader.astro";
|
||||
import { getCollection } from "astro:content";
|
||||
|
||||
// get static paths for all pages
|
||||
export async function getStaticPaths() {
|
||||
const COLLECTION_FOLDER = "pages";
|
||||
|
||||
const pages = await getCollection(
|
||||
COLLECTION_FOLDER,
|
||||
({ data }) => !data.draft,
|
||||
);
|
||||
const pages = await getSinglePage(COLLECTION_FOLDER);
|
||||
|
||||
const paths = pages.map((page) => ({
|
||||
params: {
|
||||
|
||||
@@ -2,16 +2,14 @@
|
||||
import BlogCard from "@/components/BlogCard.astro";
|
||||
import Social from "@/components/Social.astro";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
import { slugify } from "@/lib/utils/textConverter";
|
||||
import { Image } from "astro:assets";
|
||||
import { getCollection } from "astro:content";
|
||||
|
||||
// get all static paths for authors
|
||||
export async function getStaticPaths() {
|
||||
const COLLECTION_FOLDER = "authors";
|
||||
const authors = await getCollection(
|
||||
COLLECTION_FOLDER,
|
||||
({ data, slug }) => !data.draft && slug !== "-index",
|
||||
);
|
||||
const authors = await getSinglePage(COLLECTION_FOLDER);
|
||||
|
||||
const paths = authors.map((author) => ({
|
||||
params: {
|
||||
@@ -25,10 +23,10 @@ export async function getStaticPaths() {
|
||||
const { author } = Astro.props;
|
||||
const { title, social, meta_title, description, image } = author.data;
|
||||
const { Content } = await author.render();
|
||||
const posts = await getCollection(
|
||||
"blog",
|
||||
({ data, slug }) => !data.draft && slug !== "-index",
|
||||
);
|
||||
|
||||
// get all posts by author
|
||||
const BLOG_FOLDER = "blog";
|
||||
const posts = await getSinglePage(BLOG_FOLDER);
|
||||
const postFilterByAuthor = posts.filter(
|
||||
(post) => slugify(post.data.author) === slugify(title),
|
||||
);
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
---
|
||||
import AuthorCard from "@/components/AuthorCard.astro";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
import PageHeader from "@/partials/PageHeader.astro";
|
||||
import { getCollection, getEntry } from "astro:content";
|
||||
import { getEntry } from "astro:content";
|
||||
|
||||
const COLLECTION_FOLDER = "authors";
|
||||
|
||||
const authorIndex = await getEntry(COLLECTION_FOLDER, "-index");
|
||||
const authors = await getCollection(
|
||||
COLLECTION_FOLDER,
|
||||
({ data, slug }) => !data.draft && slug !== "-index",
|
||||
);
|
||||
const authors = await getSinglePage(COLLECTION_FOLDER);
|
||||
---
|
||||
|
||||
<Base title={authorIndex.data.title}>
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
---
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import PostSingle from "@/layouts/PostSingle.astro";
|
||||
import { getCollection } from "astro:content";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const COLLECTION_FOLDER = "blog";
|
||||
const posts = await getCollection(
|
||||
COLLECTION_FOLDER,
|
||||
({ data, slug }) => !data.draft && slug !== "-index",
|
||||
);
|
||||
const BLOG_FOLDER = "blog";
|
||||
const posts = await getSinglePage(BLOG_FOLDER);
|
||||
|
||||
const paths = posts.map((post) => ({
|
||||
params: {
|
||||
|
||||
@@ -3,22 +3,20 @@ import BlogCard from "@/components/BlogCard.astro";
|
||||
import Pagination from "@/components/Pagination.astro";
|
||||
import config from "@/config/config.json";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
|
||||
import { sortByDate } from "@/lib/utils/sortFunctions";
|
||||
import PageHeader from "@/partials/PageHeader.astro";
|
||||
import PostSidebar from "@/partials/PostSidebar.astro";
|
||||
import { getCollection, getEntry } from "astro:content";
|
||||
import { getEntry } from "astro:content";
|
||||
|
||||
const COLLECTION_FOLDER = "blog";
|
||||
const BLOG_FOLDER = "blog";
|
||||
|
||||
const postIndex = await getEntry(COLLECTION_FOLDER, "-index");
|
||||
const posts = await getCollection(
|
||||
COLLECTION_FOLDER,
|
||||
({ data, slug }) => !data.draft && slug !== "-index",
|
||||
);
|
||||
const allCategories = await getAllTaxonomy(COLLECTION_FOLDER, "categories");
|
||||
const categories = await getTaxonomy(COLLECTION_FOLDER, "categories");
|
||||
const tags = await getTaxonomy(COLLECTION_FOLDER, "tags");
|
||||
const postIndex = await getEntry(BLOG_FOLDER, "-index");
|
||||
const posts = await getSinglePage(BLOG_FOLDER);
|
||||
const allCategories = await getAllTaxonomy(BLOG_FOLDER, "categories");
|
||||
const categories = await getTaxonomy(BLOG_FOLDER, "categories");
|
||||
const tags = await getTaxonomy(BLOG_FOLDER, "tags");
|
||||
const sortedPosts = sortByDate(posts);
|
||||
const totalPages: number = Math.ceil(posts.length / config.settings.pagination);
|
||||
const currentPosts = sortedPosts.slice(0, config.settings.pagination);
|
||||
@@ -46,7 +44,7 @@ const currentPosts = sortedPosts.slice(0, config.settings.pagination);
|
||||
}
|
||||
</div>
|
||||
<Pagination
|
||||
section={COLLECTION_FOLDER}
|
||||
section={BLOG_FOLDER}
|
||||
currentPage={1}
|
||||
totalPages={totalPages}
|
||||
/>
|
||||
|
||||
@@ -3,23 +3,21 @@ import BlogCard from "@/components/BlogCard.astro";
|
||||
import Pagination from "@/components/Pagination.astro";
|
||||
import config from "@/config/config.json";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
import { getAllTaxonomy, getTaxonomy } from "@/lib/taxonomyParser.astro";
|
||||
import { sortByDate } from "@/lib/utils/sortFunctions";
|
||||
import PageHeader from "@/partials/PageHeader.astro";
|
||||
import PostSidebar from "@/partials/PostSidebar.astro";
|
||||
import { getCollection, getEntry } from "astro:content";
|
||||
import { getEntry } from "astro:content";
|
||||
|
||||
const COLLECTION_FOLDER = "blog";
|
||||
const BLOG_FOLDER = "blog";
|
||||
|
||||
const { slug } = Astro.params;
|
||||
const postIndex = await getEntry(COLLECTION_FOLDER, "-index");
|
||||
const posts = await getCollection(
|
||||
COLLECTION_FOLDER,
|
||||
({ data, slug }) => !data.draft && slug !== "-index",
|
||||
);
|
||||
const allCategories = await getAllTaxonomy(COLLECTION_FOLDER, "categories");
|
||||
const categories = await getTaxonomy(COLLECTION_FOLDER, "categories");
|
||||
const tags = await getTaxonomy(COLLECTION_FOLDER, "tags");
|
||||
const postIndex = await getEntry(BLOG_FOLDER, "-index");
|
||||
const posts = await getSinglePage(BLOG_FOLDER);
|
||||
const allCategories = await getAllTaxonomy(BLOG_FOLDER, "categories");
|
||||
const categories = await getTaxonomy(BLOG_FOLDER, "categories");
|
||||
const tags = await getTaxonomy(BLOG_FOLDER, "tags");
|
||||
const sortedPosts = sortByDate(posts);
|
||||
const totalPages = Math.ceil(posts.length / config.settings.pagination);
|
||||
const currentPage = slug && !isNaN(Number(slug)) ? Number(slug) : 1;
|
||||
@@ -28,11 +26,8 @@ const indexOfFirstPost = indexOfLastPost - config.settings.pagination;
|
||||
const currentPosts = sortedPosts.slice(indexOfFirstPost, indexOfLastPost);
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const COLLECTION_FOLDER = "blog";
|
||||
const posts = await getCollection(
|
||||
COLLECTION_FOLDER,
|
||||
({ data, slug }) => !data.draft && slug !== "-index",
|
||||
);
|
||||
const BLOG_FOLDER = "blog";
|
||||
const posts = await getSinglePage(BLOG_FOLDER);
|
||||
const totalPages = Math.ceil(posts.length / config.settings.pagination);
|
||||
const paths = [];
|
||||
|
||||
@@ -69,7 +64,7 @@ export async function getStaticPaths() {
|
||||
}
|
||||
</div>
|
||||
<Pagination
|
||||
section={COLLECTION_FOLDER}
|
||||
section={BLOG_FOLDER}
|
||||
currentPage={currentPage}
|
||||
totalPages={totalPages}
|
||||
/>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
---
|
||||
import BlogCard from "@/components/BlogCard.astro";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
import { getTaxonomy } from "@/lib/taxonomyParser.astro";
|
||||
import taxonomyFilter from "@/lib/utils/taxonomyFilter";
|
||||
import PageHeader from "@/partials/PageHeader.astro";
|
||||
import { getCollection } from "astro:content";
|
||||
|
||||
// get static paths for all categories
|
||||
export async function getStaticPaths() {
|
||||
const BLOG_FOLDER = "blog";
|
||||
const categories = await getTaxonomy(BLOG_FOLDER, "categories");
|
||||
@@ -18,10 +19,10 @@ export async function getStaticPaths() {
|
||||
}
|
||||
|
||||
const { category } = Astro.params;
|
||||
const posts = await getCollection(
|
||||
"blog",
|
||||
({ data, slug }) => !data.draft && slug !== "-index",
|
||||
);
|
||||
|
||||
// get posts by category
|
||||
const BLOG_FOLDER = "blog";
|
||||
const posts = await getSinglePage(BLOG_FOLDER);
|
||||
const filterByCategories = taxonomyFilter(posts, "categories", category!);
|
||||
---
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
---
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import SearchLayout from "@/layouts/Search";
|
||||
import { getCollection } from "astro:content";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
|
||||
const posts = await getCollection(
|
||||
"blog",
|
||||
({ data, slug }) => !data.draft && slug !== "-index",
|
||||
);
|
||||
const BLOG_FOLDER = "blog";
|
||||
const posts = await getSinglePage(BLOG_FOLDER);
|
||||
|
||||
// List of items to search in
|
||||
const searchList = posts.map((item) => ({
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
---
|
||||
import BlogCard from "@/components/BlogCard.astro";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
import { getTaxonomy } from "@/lib/taxonomyParser.astro";
|
||||
import taxonomyFilter from "@/lib/utils/taxonomyFilter";
|
||||
import PageHeader from "@/partials/PageHeader.astro";
|
||||
import { getCollection } from "astro:content";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const BLOG_FOLDER = "blog";
|
||||
@@ -18,11 +18,11 @@ export async function getStaticPaths() {
|
||||
}
|
||||
|
||||
const { tag } = Astro.params;
|
||||
const posts = await getCollection(
|
||||
"blog",
|
||||
({ data, slug }) => !data.draft && slug !== "-index",
|
||||
);
|
||||
const filterByTags = taxonomyFilter(posts, "categories", tag!);
|
||||
|
||||
// get posts by tag
|
||||
const BLOG_FOLDER = "blog";
|
||||
const posts = await getSinglePage(BLOG_FOLDER);
|
||||
const filterByTags = taxonomyFilter(posts, "tags", tag!);
|
||||
---
|
||||
|
||||
<Base title={tag}>
|
||||
|
||||
Reference in New Issue
Block a user