mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-19 22:53:36 +09:00
category && tag single static path modifed
This commit is contained in:
@@ -17,7 +17,7 @@ const lang = getLangFromUrl(Astro.url);
|
|||||||
{
|
{
|
||||||
categories.map((category: any) => {
|
categories.map((category: any) => {
|
||||||
const count = allCategories.filter(
|
const count = allCategories.filter(
|
||||||
(c: any) => c === category,
|
(c: any) => c === category
|
||||||
).length;
|
).length;
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import config from "@/config/config.json";
|
|||||||
|
|
||||||
export const getSinglePage = async <C extends CollectionKey>(
|
export const getSinglePage = async <C extends CollectionKey>(
|
||||||
collectionName: C,
|
collectionName: C,
|
||||||
lang: keyof ContentEntryMap,
|
lang: keyof ContentEntryMap
|
||||||
): Promise<CollectionEntry<C>[]> => {
|
): Promise<CollectionEntry<C>[]> => {
|
||||||
const { default_language } = config.settings;
|
const { default_language } = config.settings;
|
||||||
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
|
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
|
||||||
@@ -20,7 +20,7 @@ export const getSinglePage = async <C extends CollectionKey>(
|
|||||||
langCollection || default_language,
|
langCollection || default_language,
|
||||||
({ id }: any) => {
|
({ id }: any) => {
|
||||||
return id.startsWith(collectionName) && !id.endsWith("-index.md");
|
return id.startsWith(collectionName) && !id.endsWith("-index.md");
|
||||||
},
|
}
|
||||||
)) as CollectionEntry<C>[];
|
)) as CollectionEntry<C>[];
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@@ -30,7 +30,7 @@ export const getSinglePage = async <C extends CollectionKey>(
|
|||||||
|
|
||||||
export const getListPage = async <C extends CollectionKey>(
|
export const getListPage = async <C extends CollectionKey>(
|
||||||
collectionName: C,
|
collectionName: C,
|
||||||
lang: keyof ContentEntryMap,
|
lang: keyof ContentEntryMap
|
||||||
): Promise<CollectionEntry<C>[]> => {
|
): Promise<CollectionEntry<C>[]> => {
|
||||||
const { default_language } = config.settings;
|
const { default_language } = config.settings;
|
||||||
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
|
const langCollection: keyof ContentEntryMap = lang as keyof ContentEntryMap;
|
||||||
@@ -39,7 +39,7 @@ export const getListPage = async <C extends CollectionKey>(
|
|||||||
langCollection || default_language,
|
langCollection || default_language,
|
||||||
({ id }: any) => {
|
({ id }: any) => {
|
||||||
return id.startsWith(collectionName);
|
return id.startsWith(collectionName);
|
||||||
},
|
}
|
||||||
)) as CollectionEntry<C>[];
|
)) as CollectionEntry<C>[];
|
||||||
|
|
||||||
return pages;
|
return pages;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const getTaxonomy = async (collection: any, name: string) => {
|
|||||||
actualCollection as keyof ContentEntryMap,
|
actualCollection as keyof ContentEntryMap,
|
||||||
({ id }: any) => {
|
({ id }: any) => {
|
||||||
return id.startsWith("blog") && !id.endsWith("-index.md");
|
return id.startsWith("blog") && !id.endsWith("-index.md");
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
|
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
|
||||||
let taxonomies: string[] = [];
|
let taxonomies: string[] = [];
|
||||||
@@ -37,7 +37,7 @@ export const getAllTaxonomy = async (collection: any, name: string) => {
|
|||||||
actualCollection as keyof ContentEntryMap,
|
actualCollection as keyof ContentEntryMap,
|
||||||
({ id }: any) => {
|
({ id }: any) => {
|
||||||
return id.startsWith("blog") && !id.endsWith("-index.md");
|
return id.startsWith("blog") && !id.endsWith("-index.md");
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
|
const taxonomyPages = singlePages.map((page: any) => page.data[name]);
|
||||||
let taxonomies: string[] = [];
|
let taxonomies: string[] = [];
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ import { sortByDate } from "@/lib/utils/sortFunctions";
|
|||||||
import taxonomyFilter from "@/lib/utils/taxonomyFilter";
|
import taxonomyFilter from "@/lib/utils/taxonomyFilter";
|
||||||
import PageHeader from "@/partials/PageHeader.astro";
|
import PageHeader from "@/partials/PageHeader.astro";
|
||||||
import type { ContentEntryMap } from "astro:content";
|
import type { ContentEntryMap } from "astro:content";
|
||||||
|
import config from "@/config/config.json";
|
||||||
|
|
||||||
// get all static paths for categories
|
// get all static paths for categories
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
|
const { default_language } = config.settings;
|
||||||
|
|
||||||
const paths = await Promise.all(
|
const paths = await Promise.all(
|
||||||
supportedLang.map(async (lang) => {
|
supportedLang.map(async (lang) => {
|
||||||
const categories = await getTaxonomy(lang, "categories");
|
const categories = await getTaxonomy(lang, "categories");
|
||||||
@@ -24,9 +27,22 @@ export async function getStaticPaths() {
|
|||||||
category,
|
category,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
return paths.flat();
|
|
||||||
|
// Handle default path (no lang)
|
||||||
|
const defaultCategories = await getTaxonomy(default_language, "categories");
|
||||||
|
const defaultPaths = defaultCategories.map((category) => ({
|
||||||
|
params: {
|
||||||
|
lang: undefined,
|
||||||
|
category: category,
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
category,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
return [...paths.flat(), ...defaultPaths];
|
||||||
}
|
}
|
||||||
|
|
||||||
const { category, lang } = Astro.params;
|
const { category, lang } = Astro.params;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
---
|
---
|
||||||
import BlogCard from "@/components/BlogCard.astro";
|
import BlogCard from "@/components/BlogCard.astro";
|
||||||
|
import config from "@/config/config.json";
|
||||||
import Base from "@/layouts/Base.astro";
|
import Base from "@/layouts/Base.astro";
|
||||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||||
import { getTaxonomy } from "@/lib/taxonomyParser.astro";
|
import { getTaxonomy } from "@/lib/taxonomyParser.astro";
|
||||||
@@ -9,8 +10,10 @@ import taxonomyFilter from "@/lib/utils/taxonomyFilter";
|
|||||||
import PageHeader from "@/partials/PageHeader.astro";
|
import PageHeader from "@/partials/PageHeader.astro";
|
||||||
import type { ContentEntryMap } from "astro:content";
|
import type { ContentEntryMap } from "astro:content";
|
||||||
|
|
||||||
// get all static paths for categories
|
// get all static paths for tags
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
|
const { default_language } = config.settings;
|
||||||
|
|
||||||
const paths = await Promise.all(
|
const paths = await Promise.all(
|
||||||
supportedLang.map(async (lang) => {
|
supportedLang.map(async (lang) => {
|
||||||
const tags = await getTaxonomy(lang, "tags");
|
const tags = await getTaxonomy(lang, "tags");
|
||||||
@@ -24,9 +27,22 @@ export async function getStaticPaths() {
|
|||||||
tag,
|
tag,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
return paths.flat();
|
|
||||||
|
// Handle default path (no lang)
|
||||||
|
const defaultCategories = await getTaxonomy(default_language, "tags");
|
||||||
|
const defaultPaths = defaultCategories.map((tag) => ({
|
||||||
|
params: {
|
||||||
|
lang: undefined,
|
||||||
|
tag: tag,
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
tag,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
return [...paths.flat(), ...defaultPaths];
|
||||||
}
|
}
|
||||||
|
|
||||||
const { tag, lang } = Astro.params;
|
const { tag, lang } = Astro.params;
|
||||||
|
|||||||
Reference in New Issue
Block a user