mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-11 18:56:06 +09:00
Update theme to Astro v6 stable and switch to built-in Fonts API
* Updated theme to Astro v6 stable * Replaced third-party astro-font with the built-in Fonts API
This commit is contained in:
+37
-1
@@ -3,11 +3,46 @@ import react from "@astrojs/react";
|
||||
import sitemap from "@astrojs/sitemap";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import AutoImport from "astro-auto-import";
|
||||
import { defineConfig } from "astro/config";
|
||||
import { defineConfig, fontProviders } from "astro/config";
|
||||
import remarkCollapse from "remark-collapse";
|
||||
import remarkToc from "remark-toc";
|
||||
import sharp from "sharp";
|
||||
import config from "./src/config/config.json";
|
||||
import theme from "./src/config/theme.json";
|
||||
|
||||
// Helper to parse font string format: "FontName:wght@400;500;600;700"
|
||||
function parseFontString(fontStr) {
|
||||
const [name, weightPart] = fontStr.split(":");
|
||||
let weights = [400]; // default weight
|
||||
|
||||
if (weightPart) {
|
||||
// Extract weights from wght@400;500;600 format
|
||||
const weightMatch = weightPart.match(/wght@?([\d;]+)/);
|
||||
if (weightMatch) {
|
||||
weights = weightMatch[1].split(";").map((w) => parseInt(w, 10));
|
||||
}
|
||||
}
|
||||
|
||||
return { name, weights };
|
||||
}
|
||||
|
||||
// Build fonts configuration from theme.json
|
||||
const fontsConfig = Object.entries(theme.fonts.font_family)
|
||||
.filter(([key]) => !key.includes("_type")) // Filter out type entries
|
||||
.map(([key, fontStr]) => {
|
||||
const { name, weights } = parseFontString(fontStr);
|
||||
const typeKey = `${key}_type`;
|
||||
const fallback = theme.fonts.font_family[typeKey] || "sans-serif";
|
||||
|
||||
return {
|
||||
name,
|
||||
cssVariable: `--font-${key}`,
|
||||
provider: fontProviders.google(),
|
||||
weights,
|
||||
display: "swap",
|
||||
fallbacks: [fallback],
|
||||
};
|
||||
});
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
@@ -16,6 +51,7 @@ export default defineConfig({
|
||||
trailingSlash: config.site.trailing_slash ? "always" : "never",
|
||||
image: { service: sharp() },
|
||||
vite: { plugins: [tailwindcss()] },
|
||||
fonts: fontsConfig,
|
||||
integrations: [
|
||||
react(),
|
||||
sitemap(),
|
||||
|
||||
Reference in New Issue
Block a user