mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
Replace env variable with SITE config object
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
---
|
||||
import { SITE } from "src/config";
|
||||
import Hr from "./Hr.astro";
|
||||
import LinkButton from "./LinkButton.astro";
|
||||
|
||||
@@ -13,7 +14,7 @@ const { activeNav } = Astro.props;
|
||||
<a id="skip-to-content" href="#main-content">Skip to content</a>
|
||||
<div class="nav-container">
|
||||
<div class="top-nav-wrap">
|
||||
<a href="/" class="logo">{import.meta.env.PUBLIC_SITE_TITLE}</a>
|
||||
<a href="/" class="logo">{SITE.title}</a>
|
||||
<button class="hamburger-menu" aria-label="menu">
|
||||
<div class="icon-container flex">
|
||||
<div id="first-line"></div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
---
|
||||
import { SITE } from "src/config";
|
||||
import Breadcrumbs from "@components/Breadcrumbs.astro";
|
||||
import Footer from "@components/Footer.astro";
|
||||
import Header from "@components/Header.astro";
|
||||
@@ -14,7 +15,7 @@ export interface Props {
|
||||
const { frontmatter } = Astro.props;
|
||||
---
|
||||
|
||||
<Layout title={`${frontmatter.title} | ${import.meta.env.PUBLIC_SITE_TITLE}`}>
|
||||
<Layout title={`${frontmatter.title} | ${SITE.title}`}>
|
||||
<Header activeNav="about" />
|
||||
<Breadcrumbs />
|
||||
<main id="main-content">
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
---
|
||||
import { SITE } from "src/config";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import Main from "@layouts/Main.astro";
|
||||
import Header from "@components/Header.astro";
|
||||
import Footer from "@components/Footer.astro";
|
||||
import Card from "@components/Card";
|
||||
import LinkButton from "@components/LinkButton.astro";
|
||||
import type { Frontmatter } from "@utils/types";
|
||||
import type { MarkdownInstance } from "astro";
|
||||
import type { Frontmatter } from "src/types";
|
||||
|
||||
export interface Props {
|
||||
pageNum: number;
|
||||
@@ -20,7 +21,7 @@ const prev = pageNum > 1 ? "" : "disabled";
|
||||
const next = pageNum < totalPages ? "" : "disabled";
|
||||
---
|
||||
|
||||
<Layout title={`Posts | ${import.meta.env.PUBLIC_SITE_TITLE}`}>
|
||||
<Layout title={`Posts | ${SITE.title}`}>
|
||||
<Header activeNav="posts" />
|
||||
<Main pageTitle="Posts" pageDesc="All the articles I've posted.">
|
||||
<ul>
|
||||
|
||||
+2
-1
@@ -1,11 +1,12 @@
|
||||
---
|
||||
import { SITE } from "src/config";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import Header from "@components/Header.astro";
|
||||
import Footer from "@components/Footer.astro";
|
||||
import LinkButton from "@components/LinkButton.astro";
|
||||
---
|
||||
|
||||
<Layout title={`404 Not Found | ${import.meta.env.PUBLIC_SITE_TITLE}`}>
|
||||
<Layout title={`404 Not Found | ${SITE.title}`}>
|
||||
<Header />
|
||||
|
||||
<main id="main-content">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
---
|
||||
import { SITE } from "src/config";
|
||||
import Posts from "@layouts/Posts.astro";
|
||||
import PostDetails from "@layouts/PostDetails.astro";
|
||||
import getSortedPosts from "@utils/getSortedPosts";
|
||||
@@ -59,8 +60,8 @@ const currentPage =
|
||||
slug && !isNaN(Number(slug)) && totalPages.includes(Number(slug))
|
||||
? Number(slug)
|
||||
: 0;
|
||||
const lastPost = currentPage * import.meta.env.PUBLIC_POST_PER_PAGE;
|
||||
const startPost = lastPost - import.meta.env.PUBLIC_POST_PER_PAGE;
|
||||
const lastPost = currentPage * SITE.postPerPage;
|
||||
const startPost = lastPost - SITE.postPerPage;
|
||||
|
||||
const paginatedPosts = sortedPosts.slice(startPost, lastPost);
|
||||
---
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
---
|
||||
import { SITE } from "src/config";
|
||||
import Posts from "@layouts/Posts.astro";
|
||||
import getSortedPosts from "@utils/getSortedPosts";
|
||||
import getPageNumbers from "@utils/getPageNumbers";
|
||||
import type { Frontmatter } from "@utils/types";
|
||||
import type { Frontmatter } from "src/types";
|
||||
|
||||
const posts = await Astro.glob<Frontmatter>("../../contents/*.md");
|
||||
|
||||
@@ -10,10 +11,7 @@ const sortedPosts = getSortedPosts(posts);
|
||||
|
||||
const totalPages = getPageNumbers(posts.length);
|
||||
|
||||
const paginatedPosts = sortedPosts.slice(
|
||||
0,
|
||||
import.meta.env.PUBLIC_POST_PER_PAGE
|
||||
);
|
||||
const paginatedPosts = sortedPosts.slice(0, SITE.postPerPage);
|
||||
---
|
||||
|
||||
<Posts posts={paginatedPosts} pageNum={1} totalPages={totalPages.length} />
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { SITE } from "src/config";
|
||||
import rss from "@astrojs/rss";
|
||||
import type { Frontmatter } from "src/types";
|
||||
import type { MarkdownInstance } from "astro";
|
||||
@@ -12,9 +13,9 @@ const posts = Object.values(postImportResult);
|
||||
|
||||
export const get = () =>
|
||||
rss({
|
||||
title: import.meta.env.PUBLIC_SITE_TITLE,
|
||||
description: import.meta.env.PUBLIC_SITE_DESC,
|
||||
site: import.meta.env.SITE,
|
||||
title: SITE.title,
|
||||
description: SITE.desc,
|
||||
site: SITE.website,
|
||||
items: posts.map(({ frontmatter }) => ({
|
||||
link: frontmatter.slug,
|
||||
title: frontmatter.title,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
---
|
||||
import { SITE } from "src/config";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import Main from "@layouts/Main.astro";
|
||||
import Header from "@components/Header.astro";
|
||||
import Footer from "@components/Footer.astro";
|
||||
import Search from "@components/Search";
|
||||
import type { Frontmatter } from "@utils/types";
|
||||
import type { Frontmatter } from "src/types";
|
||||
|
||||
localStorage.setItem("myCat", "Tom");
|
||||
|
||||
@@ -20,7 +21,7 @@ const searchList = posts.map(({ frontmatter }) => ({
|
||||
}));
|
||||
---
|
||||
|
||||
<Layout title={`Search | ${import.meta.env.PUBLIC_SITE_TITLE}`}>
|
||||
<Layout title={`Search | ${SITE.title}`}>
|
||||
<Header activeNav="search" />
|
||||
<Main pageTitle="Search" pageDesc="Search any article ...">
|
||||
<Search client:load searchList={searchList} />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
---
|
||||
import { SITE } from "src/config";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import Main from "@layouts/Main.astro";
|
||||
import Header from "@components/Header.astro";
|
||||
@@ -42,7 +43,7 @@ const posts: MarkdownInstance<Frontmatter>[] = await Astro.glob(
|
||||
const tagPosts = getPostsByTag(posts, tag);
|
||||
---
|
||||
|
||||
<Layout title={`Tag:${tag} | ${import.meta.env.PUBLIC_SITE_TITLE}`}>
|
||||
<Layout title={`Tag:${tag} | ${SITE.title}`}>
|
||||
<Header activeNav="tags" />
|
||||
<Main
|
||||
pageTitle={`Tag:${tag}`}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
---
|
||||
import { SITE } from "src/config";
|
||||
import Header from "@components/Header.astro";
|
||||
import Footer from "@components/Footer.astro";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import Main from "@layouts/Main.astro";
|
||||
import Tag from "@components/Tag.astro";
|
||||
import getUniqueTags from "@utils/getUniqueTags";
|
||||
import type { Frontmatter } from "@utils/types";
|
||||
import type { Frontmatter } from "src/types";
|
||||
|
||||
const posts = await Astro.glob<Frontmatter>("../../contents/*.md");
|
||||
|
||||
let tags = getUniqueTags(posts);
|
||||
---
|
||||
|
||||
<Layout title={`Tags | ${import.meta.env.PUBLIC_SITE_TITLE}`}>
|
||||
<Layout title={`Tags | ${SITE.title}`}>
|
||||
<Header activeNav="tags" />
|
||||
<Main pageTitle="Tags" pageDesc="All the tags used in posts.">
|
||||
<ul>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { SITE } from "src/config";
|
||||
|
||||
const getPageNumbers = (numberOfPosts: number) => {
|
||||
const numberOfPages =
|
||||
numberOfPosts / Number(import.meta.env.PUBLIC_POST_PER_PAGE);
|
||||
const numberOfPages = numberOfPosts / Number(SITE.postPerPage);
|
||||
|
||||
let pageNumbers: number[] = [];
|
||||
for (let i = 1; i <= Math.ceil(numberOfPages); i++) {
|
||||
|
||||
Reference in New Issue
Block a user