mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-19 22:53:36 +09:00
Updated to Astro v5
This commit is contained in:
Executable
+163
@@ -0,0 +1,163 @@
|
||||
import { glob } from "astro/loaders";
|
||||
import { defineCollection, z } from "astro:content";
|
||||
|
||||
// Post collection schema
|
||||
const blogCollection = defineCollection({
|
||||
loader: glob({ pattern: "**/*.{md,mdx}", base: "src/content/blog" }),
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
meta_title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
date: z.date().optional(),
|
||||
image: z.string().optional(),
|
||||
author: z.string().default("Admin"),
|
||||
categories: z.array(z.string()).default(["others"]),
|
||||
tags: z.array(z.string()).default(["others"]),
|
||||
draft: z.boolean().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
// Author collection schema
|
||||
const authorsCollection = defineCollection({
|
||||
loader: glob({ pattern: "**/*.{md,mdx}", base: "src/content/authors" }),
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
meta_title: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
image: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
social: z
|
||||
.array(
|
||||
z
|
||||
.object({
|
||||
name: z.string().optional(),
|
||||
icon: z.string().optional(),
|
||||
link: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
)
|
||||
.optional(),
|
||||
draft: z.boolean().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
// Pages collection schema
|
||||
const pagesCollection = defineCollection({
|
||||
loader: glob({ pattern: "**/*.{md,mdx}", base: "src/content/pages" }),
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
meta_title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
image: z.string().optional(),
|
||||
draft: z.boolean().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
// about collection schema
|
||||
const aboutCollection = defineCollection({
|
||||
loader: glob({ pattern: "**/*.{md,mdx}", base: "src/content/about" }),
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
meta_title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
image: z.string().optional(),
|
||||
draft: z.boolean().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
// contact collection schema
|
||||
const contactCollection = defineCollection({
|
||||
loader: glob({ pattern: "**/*.{md,mdx}", base: "src/content/contact" }),
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
meta_title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
image: z.string().optional(),
|
||||
draft: z.boolean().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
// Homepage collection schema
|
||||
const homepageCollection = defineCollection({
|
||||
loader: glob({ pattern: "**/-*.{md,mdx}", base: "src/content/homepage" }),
|
||||
schema: z.object({
|
||||
banner: z.object({
|
||||
title: z.string(),
|
||||
content: z.string(),
|
||||
image: z.string(),
|
||||
button: z.object({
|
||||
enable: z.boolean(),
|
||||
label: z.string(),
|
||||
link: z.string(),
|
||||
}),
|
||||
}),
|
||||
features: z.array(
|
||||
z.object({
|
||||
title: z.string(),
|
||||
image: z.string(),
|
||||
content: z.string(),
|
||||
bulletpoints: z.array(z.string()),
|
||||
button: z.object({
|
||||
enable: z.boolean(),
|
||||
label: z.string(),
|
||||
link: z.string(),
|
||||
}),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
});
|
||||
|
||||
// Call to Action collection schema
|
||||
const ctaSectionCollection = defineCollection({
|
||||
loader: glob({
|
||||
pattern: "call-to-action.{md,mdx}",
|
||||
base: "src/content/sections",
|
||||
}),
|
||||
schema: z.object({
|
||||
enable: z.boolean(),
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
image: z.string(),
|
||||
button: z.object({
|
||||
enable: z.boolean(),
|
||||
label: z.string(),
|
||||
link: z.string(),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
// Testimonials Section collection schema
|
||||
const testimonialSectionCollection = defineCollection({
|
||||
loader: glob({
|
||||
pattern: "testimonial.{md,mdx}",
|
||||
base: "src/content/sections",
|
||||
}),
|
||||
schema: z.object({
|
||||
enable: z.boolean(),
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
testimonials: z.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
avatar: z.string(),
|
||||
designation: z.string(),
|
||||
content: z.string(),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
});
|
||||
|
||||
// Export collections
|
||||
export const collections = {
|
||||
// Pages
|
||||
homepage: homepageCollection,
|
||||
blog: blogCollection,
|
||||
authors: authorsCollection,
|
||||
pages: pagesCollection,
|
||||
about: aboutCollection,
|
||||
contact: contactCollection,
|
||||
|
||||
// sections
|
||||
ctaSection: ctaSectionCollection,
|
||||
testimonialSection: testimonialSectionCollection,
|
||||
};
|
||||
@@ -1,57 +0,0 @@
|
||||
import { defineCollection, z } from "astro:content";
|
||||
|
||||
// Post collection schema
|
||||
const blogCollection = defineCollection({
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
meta_title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
date: z.date().optional(),
|
||||
image: z.string().optional(),
|
||||
author: z.string().default("Admin"),
|
||||
categories: z.array(z.string()).default(["others"]),
|
||||
tags: z.array(z.string()).default(["others"]),
|
||||
draft: z.boolean().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
// Author collection schema
|
||||
const authorsCollection = defineCollection({
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
meta_title: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
image: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
social: z
|
||||
.array(
|
||||
z
|
||||
.object({
|
||||
name: z.string().optional(),
|
||||
icon: z.string().optional(),
|
||||
link: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
)
|
||||
.optional(),
|
||||
draft: z.boolean().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
// Pages collection schema
|
||||
const pagesCollection = defineCollection({
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
meta_title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
image: z.string().optional(),
|
||||
draft: z.boolean().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
// Export collections
|
||||
export const collections = {
|
||||
blog: blogCollection,
|
||||
authors: authorsCollection,
|
||||
pages: pagesCollection,
|
||||
};
|
||||
Vendored
-2
@@ -1,2 +0,0 @@
|
||||
/// <reference path="../.astro/types.d.ts" />
|
||||
/// <reference types="astro/client" />
|
||||
@@ -7,7 +7,7 @@ import Footer from "@/partials/Footer.astro";
|
||||
import Header from "@/partials/Header.astro";
|
||||
import "@/styles/main.scss";
|
||||
import { AstroFont } from "astro-font";
|
||||
import { ViewTransitions } from "astro:transitions";
|
||||
import { ClientRouter } from "astro:transitions";
|
||||
import SearchModal from "./helpers/SearchModal";
|
||||
|
||||
// font families
|
||||
@@ -111,7 +111,7 @@ const { title, meta_title, description, image, noindex, canonical } =
|
||||
)}
|
||||
/>
|
||||
|
||||
<ViewTransitions />
|
||||
<ClientRouter />
|
||||
|
||||
<!-- author from config.json -->
|
||||
<meta name="author" content={config.metadata.meta_author} />
|
||||
|
||||
@@ -8,13 +8,14 @@ import similarItems from "@/lib/utils/similarItems";
|
||||
import { humanize, markdownify, slugify } from "@/lib/utils/textConverter";
|
||||
import { FaRegClock, FaRegFolder, FaRegUserCircle } from "react-icons/fa";
|
||||
import ImageMod from "./components/ImageMod.astro";
|
||||
import { render } from "astro:content";
|
||||
|
||||
const COLLECTION_FOLDER = "blog";
|
||||
const { post } = Astro.props;
|
||||
|
||||
const posts = await getSinglePage(COLLECTION_FOLDER);
|
||||
const similarPosts = similarItems(post, posts);
|
||||
const { Content } = await post.render();
|
||||
const { Content } = await render(post);
|
||||
const { title, description, author, categories, image, date, tags } = post.data;
|
||||
---
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ const { title, image, social } = data.data;
|
||||
)
|
||||
}
|
||||
<h4 class="mb-3">
|
||||
<a href={`/authors/${data.slug}`}>{title}</a>
|
||||
<a href={`/authors/${data.id}`}>{title}</a>
|
||||
</h4>
|
||||
<p class="mb-4">
|
||||
{plainify(data.body?.slice(0, 100))}
|
||||
|
||||
@@ -27,7 +27,7 @@ const { title, image, date, author, categories } = data.data;
|
||||
)
|
||||
}
|
||||
<h4 class="mb-3">
|
||||
<a href={`/${blog_folder}/${data.slug}`}>
|
||||
<a href={`/${blog_folder}/${data.id}`}>
|
||||
{title}
|
||||
</a>
|
||||
</h4>
|
||||
@@ -52,10 +52,7 @@ const { title, image, date, author, categories } = data.data;
|
||||
{date && <li class="inline-block">{dateFormat(date)}</li>}
|
||||
</ul>
|
||||
<p class="mb-6">{plainify(data.body?.slice(0, Number(summary_length)))}</p>
|
||||
<a
|
||||
class="btn btn-outline-primary btn-sm"
|
||||
href={`/${blog_folder}/${data.slug}`}
|
||||
>
|
||||
<a class="btn btn-outline-primary btn-sm" href={`/${blog_folder}/${data.id}`}>
|
||||
read more
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from "astro:content";
|
||||
|
||||
export const getSinglePage = async <C extends CollectionKey>(
|
||||
collectionName: C,
|
||||
collectionName: C
|
||||
): Promise<CollectionEntry<C>[]> => {
|
||||
const allPages = await getCollection(collectionName);
|
||||
const removeIndex = allPages.filter((data) => data.id.match(/^(?!-)/));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { getSinglePage } from "@/lib/contentParser.astro";
|
||||
import PageHeader from "@/partials/PageHeader.astro";
|
||||
import { render } from "astro:content";
|
||||
|
||||
// get static paths for all pages
|
||||
export async function getStaticPaths() {
|
||||
@@ -11,7 +12,7 @@ export async function getStaticPaths() {
|
||||
|
||||
const paths = pages.map((page) => ({
|
||||
params: {
|
||||
regular: page.slug,
|
||||
regular: page.id,
|
||||
},
|
||||
props: { page },
|
||||
}));
|
||||
@@ -20,7 +21,7 @@ export async function getStaticPaths() {
|
||||
|
||||
const { page } = Astro.props;
|
||||
const { title, meta_title, description, image } = page.data;
|
||||
const { Content } = await page.render();
|
||||
const { Content } = await render(page);
|
||||
---
|
||||
|
||||
<Base
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
import ImageMod from "@/components/ImageMod.astro";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import { markdownify } from "@/lib/utils/textConverter";
|
||||
import { getEntry } from "astro:content";
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
import { getEntry, render } from "astro:content";
|
||||
|
||||
const about = await getEntry("about", "-index");
|
||||
const { Content } = await about.render();
|
||||
const about = (await getEntry("about", "-index")) as CollectionEntry<"about">;
|
||||
const { Content } = await render(about);
|
||||
const { title, description, meta_title, image } = about.data;
|
||||
---
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ 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 { render } from "astro:content";
|
||||
|
||||
// get all static paths for authors
|
||||
export async function getStaticPaths() {
|
||||
@@ -13,7 +14,7 @@ export async function getStaticPaths() {
|
||||
|
||||
const paths = authors.map((author) => ({
|
||||
params: {
|
||||
single: author.slug,
|
||||
single: author.id,
|
||||
},
|
||||
props: { author },
|
||||
}));
|
||||
@@ -22,13 +23,13 @@ export async function getStaticPaths() {
|
||||
|
||||
const { author } = Astro.props;
|
||||
const { title, social, meta_title, description, image } = author.data;
|
||||
const { Content } = await author.render();
|
||||
const { Content } = await render(author);
|
||||
|
||||
// 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),
|
||||
(post) => slugify(post.data.author) === slugify(title)
|
||||
);
|
||||
---
|
||||
|
||||
|
||||
@@ -3,11 +3,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 { getEntry } from "astro:content";
|
||||
import { getEntry, type CollectionEntry } from "astro:content";
|
||||
|
||||
const COLLECTION_FOLDER = "authors";
|
||||
|
||||
const authorIndex = await getEntry(COLLECTION_FOLDER, "-index");
|
||||
const authorIndex = (await getEntry(
|
||||
COLLECTION_FOLDER,
|
||||
"-index"
|
||||
)) as CollectionEntry<"authors">;
|
||||
const authors = await getSinglePage(COLLECTION_FOLDER);
|
||||
---
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function getStaticPaths() {
|
||||
|
||||
const paths = posts.map((post) => ({
|
||||
params: {
|
||||
single: post.slug,
|
||||
single: post.id,
|
||||
},
|
||||
props: { post },
|
||||
}));
|
||||
|
||||
@@ -8,11 +8,15 @@ 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 type { CollectionEntry } from "astro:content";
|
||||
import { getEntry } from "astro:content";
|
||||
|
||||
const BLOG_FOLDER = "blog";
|
||||
|
||||
const postIndex = await getEntry(BLOG_FOLDER, "-index");
|
||||
const postIndex = (await getEntry(
|
||||
BLOG_FOLDER,
|
||||
"-index"
|
||||
)) as CollectionEntry<"blog">;
|
||||
const posts = await getSinglePage(BLOG_FOLDER);
|
||||
const allCategories = await getAllTaxonomy(BLOG_FOLDER, "categories");
|
||||
const categories = await getTaxonomy(BLOG_FOLDER, "categories");
|
||||
@@ -28,7 +32,7 @@ const currentPosts = sortedPosts.slice(0, config.settings.pagination);
|
||||
image={postIndex.data.image}
|
||||
description={postIndex.data.description}
|
||||
>
|
||||
<PageHeader title={postIndex.data.title} />
|
||||
<PageHeader title={postIndex?.data.title} />
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
<div class="row gx-5">
|
||||
|
||||
@@ -8,12 +8,16 @@ 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 type { CollectionEntry } from "astro:content";
|
||||
import { getEntry } from "astro:content";
|
||||
|
||||
const BLOG_FOLDER = "blog";
|
||||
|
||||
const { slug } = Astro.params;
|
||||
const postIndex = await getEntry(BLOG_FOLDER, "-index");
|
||||
const postIndex = (await getEntry(
|
||||
BLOG_FOLDER,
|
||||
"-index"
|
||||
)) as CollectionEntry<"blog">;
|
||||
const posts = await getSinglePage(BLOG_FOLDER);
|
||||
const allCategories = await getAllTaxonomy(BLOG_FOLDER, "categories");
|
||||
const categories = await getTaxonomy(BLOG_FOLDER, "categories");
|
||||
|
||||
@@ -3,8 +3,12 @@ import config from "@/config/config.json";
|
||||
import Base from "@/layouts/Base.astro";
|
||||
import PageHeader from "@/partials/PageHeader.astro";
|
||||
import { getEntry } from "astro:content";
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
|
||||
const contact = await getEntry("contact", "-index");
|
||||
const contact = (await getEntry(
|
||||
"contact",
|
||||
"-index"
|
||||
)) as CollectionEntry<"contact">;
|
||||
const { contact_form_action }: { contact_form_action: string } = config.params;
|
||||
const { title, description, meta_title, image } = contact.data;
|
||||
---
|
||||
|
||||
+17
-4
@@ -5,6 +5,7 @@ import { markdownify } from "@/lib/utils/textConverter";
|
||||
import CallToAction from "@/partials/CallToAction.astro";
|
||||
import Testimonial from "@/partials/Testimonial.astro";
|
||||
import type { Button, Feature } from "@/types";
|
||||
import type { CollectionEntry } from "astro:content";
|
||||
import { getEntry } from "astro:content";
|
||||
import { FaCheck } from "react-icons/fa";
|
||||
|
||||
@@ -18,10 +19,22 @@ interface Homepage {
|
||||
features: Feature[];
|
||||
}
|
||||
|
||||
const homepage = await getEntry("homepage", "-index");
|
||||
const testimonial = await getEntry("sections", "testimonial");
|
||||
const call_to_action = await getEntry("sections", "call-to-action");
|
||||
const { banner, features }: Homepage = homepage.data;
|
||||
const homepage = (await getEntry(
|
||||
"homepage",
|
||||
"-index"
|
||||
)) as CollectionEntry<"homepage">;
|
||||
|
||||
const testimonial = (await getEntry(
|
||||
"testimonialSection",
|
||||
"testimonial"
|
||||
)) as CollectionEntry<"testimonialSection">;
|
||||
|
||||
const call_to_action = (await getEntry(
|
||||
"ctaSection",
|
||||
"call-to-action"
|
||||
)) as CollectionEntry<"ctaSection">;
|
||||
|
||||
const { banner, features } = homepage.data as Homepage;
|
||||
---
|
||||
|
||||
<Base>
|
||||
|
||||
Reference in New Issue
Block a user