diff --git a/scripts/jsonGenerator.js b/scripts/jsonGenerator.js index f46ba22..5881da2 100644 --- a/scripts/jsonGenerator.js +++ b/scripts/jsonGenerator.js @@ -10,7 +10,6 @@ const BLOG_FOLDER = "blog"; // get data from markdown const getData = (folder, groupDepth, langIndex = 0) => { - // get paths const getPaths = languages .map((lang, index) => { const langFolder = lang.contentDir ? lang.contentDir : lang.languageCode; @@ -22,7 +21,7 @@ const getData = (folder, groupDepth, langIndex = 0) => { !filename.startsWith("-") && (filename.endsWith(".md") || filename.endsWith(".mdx")), ) - .map((filename) => { + .flatMap((filename) => { const filepath = path.join(dir, filename); const stats = fs.statSync(filepath); const isFolder = stats.isDirectory(); @@ -33,18 +32,26 @@ const getData = (folder, groupDepth, langIndex = 0) => { const file = fs.readFileSync(filepath, "utf-8"); const { data, content } = matter(file); const pathParts = filepath.split(path.sep); - const slug = - data.slug || - pathParts + + let slug; + if (data.slug) { + const slugParts = data.slug.split("/"); + slugParts[0] = BLOG_FOLDER; + slug = slugParts.join("/"); + } else { + slug = pathParts .slice(CONTENT_DEPTH) .join("/") .replace(/\.[^/.]+$/, ""); - const group = pathParts[groupDepth]; + slug = `${BLOG_FOLDER}/${slug.split("/").slice(1).join("/")}`; + } + data.slug = slug; + const group = "blog"; return { - lang: languages[langIndex].languageCode, + lang: languages[index].languageCode, // Set the correct language code dynamically group: group, - slug: slug, + slug: data.slug, frontmatter: data, content: content, }; @@ -53,9 +60,7 @@ const getData = (folder, groupDepth, langIndex = 0) => { }) .flat(); - const publishedPages = getPaths.filter( - (page) => !page.frontmatter?.draft && page, - ); + const publishedPages = getPaths.filter((page) => !page.frontmatter?.draft); return publishedPages; }; @@ -71,7 +76,7 @@ try { JSON.stringify(getData(BLOG_FOLDER, 3)), ); - // merger json files for search + // merge json files for search const posts = require(`../${JSON_FOLDER}/posts.json`); const search = [...posts]; fs.writeFileSync(`${JSON_FOLDER}/search.json`, JSON.stringify(search)); diff --git a/src/config/config.json b/src/config/config.json index f695a6e..83920f1 100755 --- a/src/config/config.json +++ b/src/config/config.json @@ -3,7 +3,7 @@ "title": "Astroplate", "base_url": "https://astroplate.netlify.app", "base_path": "/", - "trailing_slash": true, + "trailing_slash": false, "favicon": "/images/favicon.png", "logo": "/images/logo.png", "logo_darkmode": "/images/logo-darkmode.png", diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index 9c5a34b..e539626 100755 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -9,6 +9,7 @@ import "@/styles/main.scss"; import { AstroFont } from "astro-font"; import { ViewTransitions } from "astro:transitions"; import SearchModal from "./helpers/SearchModal"; +import { getLangFromUrl } from "@/lib/utils/languageParser"; // font families const pf = theme.fonts.font_family.primary; @@ -40,6 +41,8 @@ export interface Props { // distructure frontmatters const { title, meta_title, description, image, noindex, canonical, lang } = Astro.props; + +const language = lang || getLangFromUrl(Astro.url); --- @@ -108,7 +111,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } = @@ -121,7 +124,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } = @@ -129,7 +132,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } = @@ -142,7 +145,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } = @@ -150,7 +153,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } = @@ -174,7 +177,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } =