From 2379fb3598faa501311e5e3e565ad1272fa3c7aa Mon Sep 17 00:00:00 2001 From: Mukles Date: Thu, 16 May 2024 10:39:54 +0600 Subject: [PATCH 1/7] refactor darkmode --- scripts/removeDarkmode.js | 140 +++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 55 deletions(-) diff --git a/scripts/removeDarkmode.js b/scripts/removeDarkmode.js index 7f781ee..b04b2e7 100644 --- a/scripts/removeDarkmode.js +++ b/scripts/removeDarkmode.js @@ -1,66 +1,96 @@ const fs = require("fs"); const path = require("path"); -const rootDirs = ["src/pages", "src/hooks", "src/layouts", "src/styles"]; +(function () { + const rootDirs = ["src/pages", "src/hooks", "src/layouts", "src/styles"]; -const configFiles = [ - { - filePath: "tailwind.config.js", - patterns: ["darkmode:\\s*{[^}]*},", 'darkMode:\\s*"class",'], - }, - { filePath: "src/config/theme.json", patterns: ["colors.darkmode"] }, -]; + const deleteAssetList = [ + "public/images/logo-darkmode.png", + "src/layouts/components/ThemeSwitcher.astro", + ]; -rootDirs.forEach(removeDarkModeFromPages); -configFiles.forEach(removeDarkMode); + const configFiles = [ + { + filePath: "tailwind.config.js", + patterns: ["darkmode:\\s*{[^}]*},", 'darkMode:\\s*"class",'], + }, + { filePath: "src/config/theme.json", patterns: ["colors.darkmode"] }, + ]; -function removeDarkModeFromFiles(filePath, regexPatterns) { - const fileContent = fs.readFileSync(filePath, "utf8"); - let updatedContent = fileContent; - regexPatterns.forEach((pattern) => { - const regex = new RegExp(pattern, "g"); - updatedContent = updatedContent.replace(regex, ""); - }); - fs.writeFileSync(filePath, updatedContent, "utf8"); -} + const filePaths = [ + { + filePath: "src/layouts/partials/Header.astro", + patterns: [ + "]+)?\\s*(?:\\/\\>|>([\\s\\S]*?)<\\/ThemeSwitchers*>)", + ], + }, + ]; -function removeDarkModeFromPages(directoryPath) { - const files = fs.readdirSync(directoryPath); - - files.forEach((file) => { - const filePath = path.join(directoryPath, file); - const stats = fs.statSync(filePath); - if (stats.isDirectory()) { - removeDarkModeFromPages(filePath); - } else if (stats.isFile()) { - removeDarkModeFromFiles(filePath, [ - '(?:(?!["])\\S)*dark:(?:(?![,;"])\\S)*', - ]); - } - }); -} - -function removeDarkMode(configFile) { - const { filePath, patterns } = configFile; - if (filePath === "tailwind.config.js") { + filePaths.forEach(({ filePath, patterns }) => { removeDarkModeFromFiles(filePath, patterns); - } else { - const contentFile = JSON.parse(fs.readFileSync(filePath, "utf8")); - patterns.forEach((pattern) => deleteNestedProperty(contentFile, pattern)); - fs.writeFileSync(filePath, JSON.stringify(contentFile)); - } -} + }); -function deleteNestedProperty(obj, propertyPath) { - const properties = propertyPath.split("."); - let currentObj = obj; - for (let i = 0; i < properties.length - 1; i++) { - const property = properties[i]; - if (currentObj.hasOwnProperty(property)) { - currentObj = currentObj[property]; - } else { - return; // Property not found, no need to continue + deleteAssetList.forEach(deleteAsset); + function deleteAsset(asset) { + try { + fs.unlinkSync(asset); + console.log(`${path.basename(asset)} deleted successfully!`); + } catch (error) { + console.error(`${asset} not found`); } } - delete currentObj[properties[properties.length - 1]]; -} + + rootDirs.forEach(removeDarkModeFromPages); + configFiles.forEach(removeDarkMode); + + function removeDarkModeFromFiles(filePath, regexPatterns) { + const fileContent = fs.readFileSync(filePath, "utf8"); + let updatedContent = fileContent; + regexPatterns.forEach((pattern) => { + const regex = new RegExp(pattern, "g"); + updatedContent = updatedContent.replace(regex, ""); + }); + fs.writeFileSync(filePath, updatedContent, "utf8"); + } + + function removeDarkModeFromPages(directoryPath) { + const files = fs.readdirSync(directoryPath); + + files.forEach((file) => { + const filePath = path.join(directoryPath, file); + const stats = fs.statSync(filePath); + if (stats.isDirectory()) { + removeDarkModeFromPages(filePath); + } else if (stats.isFile()) { + removeDarkModeFromFiles(filePath, [ + '(?:(?!["])\\S)*dark:(?:(?![,;"])\\S)*', + ]); + } + }); + } + + function removeDarkMode(configFile) { + const { filePath, patterns } = configFile; + if (filePath === "tailwind.config.js") { + removeDarkModeFromFiles(filePath, patterns); + } else { + const contentFile = JSON.parse(fs.readFileSync(filePath, "utf8")); + patterns.forEach((pattern) => deleteNestedProperty(contentFile, pattern)); + fs.writeFileSync(filePath, JSON.stringify(contentFile)); + } + } + + function deleteNestedProperty(obj, propertyPath) { + const properties = propertyPath.split("."); + let currentObj = obj; + for (let i = 0; i < properties.length - 1; i++) { + const property = properties[i]; + if (currentObj.hasOwnProperty(property)) { + currentObj = currentObj[property]; + } else { + return; // Property not found, no need to continue + } + } + delete currentObj[properties[properties.length - 1]]; + } +})(); From d5e012e6f8d3f18954e327c3354e024cb7a6fdda Mon Sep 17 00:00:00 2001 From: Al Murad Uzzaman Date: Thu, 23 May 2024 15:39:53 +0600 Subject: [PATCH 2/7] changed the content folder structure && fixed breadcrumps --- scripts/jsonGenerator.js | 11 +-- src/config/config.json | 2 +- src/content/about/config.ts | 11 +++ .../about => about/english}/-index.md | 0 .../{french/about => about/french}/-index.md | 2 +- src/content/authors/config.ts | 29 ++++++++ .../authors => authors/english}/-index.md | 0 .../authors => authors/english}/john-doe.md | 0 .../authors => authors/english}/sam-wilson.md | 0 .../english}/william-jacob.md | 0 .../authors => authors/french}/-index.md | 0 .../authors => authors/french}/john-doe.md | 0 .../authors => authors/french}/sam-wilson.md | 0 .../french}/william-jacob.md | 0 src/content/blog/config.ts | 33 +++++++++ .../{english/blog => blog/english}/-index.md | 0 .../{english/blog => blog/english}/post-1.md | 0 .../{english/blog => blog/english}/post-2.md | 0 .../{english/blog => blog/english}/post-3.md | 0 .../{english/blog => blog/english}/post-4.md | 0 .../{french/blog => blog/french}/-index.md | 0 .../{french/blog => blog/french}/post-1.md | 0 .../{french/blog => blog/french}/post-2.md | 0 .../{french/blog => blog/french}/post-3.md | 0 .../{french/blog => blog/french}/post-4.md | 0 src/content/contact/config.ts | 14 ++++ .../contact => contact/english}/-index.md | 0 .../contact => contact/french}/-index.md | 0 src/content/homepage/config.ts | 42 ++++++++++++ .../homepage => homepage/english}/-index.md | 0 .../homepage => homepage/french}/-index.md | 2 +- src/content/pages/config.ts | 24 +++++++ .../pages => pages/english}/elements.mdx | 0 .../pages => pages/english}/privacy-policy.md | 0 .../pages => pages/french}/elements.mdx | 0 .../pages => pages/french}/privacy-policy.md | 0 src/content/sections/config.ts | 28 ++++++++ .../english}/call-to-action.md | 0 .../english}/testimonial.md | 0 .../french}/call-to-action.md | 0 .../french}/testimonial.md | 0 src/layouts/components/BlogCard.astro | 5 ++ src/layouts/components/Breadcrumbs.astro | 7 +- src/layouts/partials/Testimonial.astro | 2 +- src/lib/contentParser.astro | 68 ++++++++++++++++++- src/lib/taxonomyParser.astro | 16 ++--- src/pages/[...lang]/[regular].astro | 2 +- src/pages/[...lang]/about.astro | 7 +- src/pages/[...lang]/authors/[single].astro | 6 +- src/pages/[...lang]/authors/index.astro | 2 +- src/pages/[...lang]/blog/[single].astro | 4 +- src/pages/[...lang]/blog/index.astro | 2 +- src/pages/[...lang]/contact.astro | 6 +- src/pages/[...lang]/index.astro | 30 +++----- 54 files changed, 295 insertions(+), 60 deletions(-) create mode 100755 src/content/about/config.ts rename src/content/{english/about => about/english}/-index.md (100%) rename src/content/{french/about => about/french}/-index.md (92%) create mode 100755 src/content/authors/config.ts rename src/content/{english/authors => authors/english}/-index.md (100%) rename src/content/{english/authors => authors/english}/john-doe.md (100%) rename src/content/{english/authors => authors/english}/sam-wilson.md (100%) rename src/content/{english/authors => authors/english}/william-jacob.md (100%) rename src/content/{french/authors => authors/french}/-index.md (100%) rename src/content/{french/authors => authors/french}/john-doe.md (100%) rename src/content/{french/authors => authors/french}/sam-wilson.md (100%) rename src/content/{french/authors => authors/french}/william-jacob.md (100%) create mode 100755 src/content/blog/config.ts rename src/content/{english/blog => blog/english}/-index.md (100%) rename src/content/{english/blog => blog/english}/post-1.md (100%) rename src/content/{english/blog => blog/english}/post-2.md (100%) rename src/content/{english/blog => blog/english}/post-3.md (100%) rename src/content/{english/blog => blog/english}/post-4.md (100%) rename src/content/{french/blog => blog/french}/-index.md (100%) rename src/content/{french/blog => blog/french}/post-1.md (100%) rename src/content/{french/blog => blog/french}/post-2.md (100%) rename src/content/{french/blog => blog/french}/post-3.md (100%) rename src/content/{french/blog => blog/french}/post-4.md (100%) create mode 100755 src/content/contact/config.ts rename src/content/{english/contact => contact/english}/-index.md (100%) rename src/content/{french/contact => contact/french}/-index.md (100%) create mode 100755 src/content/homepage/config.ts rename src/content/{english/homepage => homepage/english}/-index.md (100%) rename src/content/{french/homepage => homepage/french}/-index.md (99%) create mode 100755 src/content/pages/config.ts rename src/content/{english/pages => pages/english}/elements.mdx (100%) rename src/content/{english/pages => pages/english}/privacy-policy.md (100%) rename src/content/{french/pages => pages/french}/elements.mdx (100%) rename src/content/{french/pages => pages/french}/privacy-policy.md (100%) create mode 100755 src/content/sections/config.ts rename src/content/{english/sections => sections/english}/call-to-action.md (100%) rename src/content/{english/sections => sections/english}/testimonial.md (100%) rename src/content/{french/sections => sections/french}/call-to-action.md (100%) rename src/content/{french/sections => sections/french}/testimonial.md (100%) diff --git a/scripts/jsonGenerator.js b/scripts/jsonGenerator.js index f63091a..f46ba22 100644 --- a/scripts/jsonGenerator.js +++ b/scripts/jsonGenerator.js @@ -9,11 +9,12 @@ const CONTENT_DEPTH = 3; const BLOG_FOLDER = "blog"; // get data from markdown -const getData = (folder, groupDepth) => { +const getData = (folder, groupDepth, langIndex = 0) => { // get paths const getPaths = languages - .map((lang) => { - const dir = path.join(CONTENT_ROOT, lang.contentDir, folder); + .map((lang, index) => { + const langFolder = lang.contentDir ? lang.contentDir : lang.languageCode; + const dir = path.join(CONTENT_ROOT, folder, langFolder); return fs .readdirSync(dir) .filter( @@ -27,7 +28,7 @@ const getData = (folder, groupDepth) => { const isFolder = stats.isDirectory(); if (isFolder) { - return getData(filepath, groupDepth); + return getData(filepath, groupDepth, index); } else { const file = fs.readFileSync(filepath, "utf-8"); const { data, content } = matter(file); @@ -41,7 +42,7 @@ const getData = (folder, groupDepth) => { const group = pathParts[groupDepth]; return { - lang: lang.languageCode, + lang: languages[langIndex].languageCode, group: group, slug: slug, frontmatter: data, diff --git a/src/config/config.json b/src/config/config.json index 83920f1..f695a6e 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": false, + "trailing_slash": true, "favicon": "/images/favicon.png", "logo": "/images/logo.png", "logo_darkmode": "/images/logo-darkmode.png", diff --git a/src/content/about/config.ts b/src/content/about/config.ts new file mode 100755 index 0000000..71ddbf1 --- /dev/null +++ b/src/content/about/config.ts @@ -0,0 +1,11 @@ +import { z } from "zod"; + +const AboutSchema = z.object({ + title: z.string(), + meta_title: z.string().optional(), + description: z.string().optional(), + image: z.string(), + draft: z.boolean().optional(), +}); + +export default AboutSchema; diff --git a/src/content/english/about/-index.md b/src/content/about/english/-index.md similarity index 100% rename from src/content/english/about/-index.md rename to src/content/about/english/-index.md diff --git a/src/content/french/about/-index.md b/src/content/about/french/-index.md similarity index 92% rename from src/content/french/about/-index.md rename to src/content/about/french/-index.md index a4ac128..041c6ad 100644 --- a/src/content/french/about/-index.md +++ b/src/content/about/french/-index.md @@ -6,4 +6,4 @@ image: "/images/avatar.png" draft: false --- -L'entreprise elle-même est une entreprise très prospère. Ils ne connaissent pas les bienfaits du corps, ou sauf qu'ils le recevront à d'autres moments, le tout, les temps de travail, qu'il déteste à partir de ce moment mais. Il fuit les plaisirs perçus pour être supposés n'être rien, tout ou, et la douleur est ce qui est la plus grande option, car cela lui est facile, et avec ce que cela s'ensuit, ils lui procurent de la douleur et ainsi de suite ! Car ledit expédient de la vérité repousse le plaisir et empêche la douleur, ils fournissent comme si \ No newline at end of file +L'entreprise elle-même est une entreprise très prospère. Ils ne connaissent pas les bienfaits du corps, ou sauf qu'ils le recevront à d'autres moments, le tout, les temps de travail, qu'il déteste à partir de ce moment mais. Il fuit les plaisirs perçus pour être supposés n'être rien, tout ou, et la douleur est ce qui est la plus grande option, car cela lui est facile, et avec ce que cela s'ensuit, ils lui procurent de la douleur et ainsi de suite ! Car ledit expédient de la vérité repousse le plaisir et empêche la douleur, ils fournissent comme si diff --git a/src/content/authors/config.ts b/src/content/authors/config.ts new file mode 100755 index 0000000..d0eb2e1 --- /dev/null +++ b/src/content/authors/config.ts @@ -0,0 +1,29 @@ +import { defineCollection, z } from "astro:content"; + +// 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(), + }), +}); + +// Export collections +export const collections = { + authors: authorsCollection, +}; diff --git a/src/content/english/authors/-index.md b/src/content/authors/english/-index.md similarity index 100% rename from src/content/english/authors/-index.md rename to src/content/authors/english/-index.md diff --git a/src/content/english/authors/john-doe.md b/src/content/authors/english/john-doe.md similarity index 100% rename from src/content/english/authors/john-doe.md rename to src/content/authors/english/john-doe.md diff --git a/src/content/english/authors/sam-wilson.md b/src/content/authors/english/sam-wilson.md similarity index 100% rename from src/content/english/authors/sam-wilson.md rename to src/content/authors/english/sam-wilson.md diff --git a/src/content/english/authors/william-jacob.md b/src/content/authors/english/william-jacob.md similarity index 100% rename from src/content/english/authors/william-jacob.md rename to src/content/authors/english/william-jacob.md diff --git a/src/content/french/authors/-index.md b/src/content/authors/french/-index.md similarity index 100% rename from src/content/french/authors/-index.md rename to src/content/authors/french/-index.md diff --git a/src/content/french/authors/john-doe.md b/src/content/authors/french/john-doe.md similarity index 100% rename from src/content/french/authors/john-doe.md rename to src/content/authors/french/john-doe.md diff --git a/src/content/french/authors/sam-wilson.md b/src/content/authors/french/sam-wilson.md similarity index 100% rename from src/content/french/authors/sam-wilson.md rename to src/content/authors/french/sam-wilson.md diff --git a/src/content/french/authors/william-jacob.md b/src/content/authors/french/william-jacob.md similarity index 100% rename from src/content/french/authors/william-jacob.md rename to src/content/authors/french/william-jacob.md diff --git a/src/content/blog/config.ts b/src/content/blog/config.ts new file mode 100755 index 0000000..e2f906b --- /dev/null +++ b/src/content/blog/config.ts @@ -0,0 +1,33 @@ +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(), + }), +}); + +// 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, + pages: pagesCollection, +}; diff --git a/src/content/english/blog/-index.md b/src/content/blog/english/-index.md similarity index 100% rename from src/content/english/blog/-index.md rename to src/content/blog/english/-index.md diff --git a/src/content/english/blog/post-1.md b/src/content/blog/english/post-1.md similarity index 100% rename from src/content/english/blog/post-1.md rename to src/content/blog/english/post-1.md diff --git a/src/content/english/blog/post-2.md b/src/content/blog/english/post-2.md similarity index 100% rename from src/content/english/blog/post-2.md rename to src/content/blog/english/post-2.md diff --git a/src/content/english/blog/post-3.md b/src/content/blog/english/post-3.md similarity index 100% rename from src/content/english/blog/post-3.md rename to src/content/blog/english/post-3.md diff --git a/src/content/english/blog/post-4.md b/src/content/blog/english/post-4.md similarity index 100% rename from src/content/english/blog/post-4.md rename to src/content/blog/english/post-4.md diff --git a/src/content/french/blog/-index.md b/src/content/blog/french/-index.md similarity index 100% rename from src/content/french/blog/-index.md rename to src/content/blog/french/-index.md diff --git a/src/content/french/blog/post-1.md b/src/content/blog/french/post-1.md similarity index 100% rename from src/content/french/blog/post-1.md rename to src/content/blog/french/post-1.md diff --git a/src/content/french/blog/post-2.md b/src/content/blog/french/post-2.md similarity index 100% rename from src/content/french/blog/post-2.md rename to src/content/blog/french/post-2.md diff --git a/src/content/french/blog/post-3.md b/src/content/blog/french/post-3.md similarity index 100% rename from src/content/french/blog/post-3.md rename to src/content/blog/french/post-3.md diff --git a/src/content/french/blog/post-4.md b/src/content/blog/french/post-4.md similarity index 100% rename from src/content/french/blog/post-4.md rename to src/content/blog/french/post-4.md diff --git a/src/content/contact/config.ts b/src/content/contact/config.ts new file mode 100755 index 0000000..349b955 --- /dev/null +++ b/src/content/contact/config.ts @@ -0,0 +1,14 @@ +import { defineCollection, z } from "astro:content"; + +const contactCollection = defineCollection({ + schema: z.object({ + title: z.string(), + meta_title: z.string().optional(), + description: z.string(), + draft: z.boolean().optional(), + }), +}); + +export const collections = { + contact: contactCollection, +}; diff --git a/src/content/english/contact/-index.md b/src/content/contact/english/-index.md similarity index 100% rename from src/content/english/contact/-index.md rename to src/content/contact/english/-index.md diff --git a/src/content/french/contact/-index.md b/src/content/contact/french/-index.md similarity index 100% rename from src/content/french/contact/-index.md rename to src/content/contact/french/-index.md diff --git a/src/content/homepage/config.ts b/src/content/homepage/config.ts new file mode 100755 index 0000000..0262957 --- /dev/null +++ b/src/content/homepage/config.ts @@ -0,0 +1,42 @@ +import { defineCollection, z } from "astro:content"; + +// Banner schema +const bannerSchema = z.object({ + title: z.string(), + content: z.string(), + image: z.string(), + button: z.object({ + enable: z.boolean(), + label: z.string(), + link: z.string(), + }), +}); + +// Features schema +const featureSchema = 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().optional(), + link: z.string().optional(), + }), +}); + +// Main content schema +const contentSchema = z.object({ + banner: bannerSchema, + features: z.array(featureSchema), +}); + +// Define the collection +const contentCollection = defineCollection({ + schema: contentSchema, +}); + +// Export collections +export const collections = { + content: contentCollection, +}; diff --git a/src/content/english/homepage/-index.md b/src/content/homepage/english/-index.md similarity index 100% rename from src/content/english/homepage/-index.md rename to src/content/homepage/english/-index.md diff --git a/src/content/french/homepage/-index.md b/src/content/homepage/french/-index.md similarity index 99% rename from src/content/french/homepage/-index.md rename to src/content/homepage/french/-index.md index d02c12b..be96b3f 100755 --- a/src/content/french/homepage/-index.md +++ b/src/content/homepage/french/-index.md @@ -50,4 +50,4 @@ features: enable: false label: "" link: "" ---- \ No newline at end of file +--- diff --git a/src/content/pages/config.ts b/src/content/pages/config.ts new file mode 100755 index 0000000..b159fc5 --- /dev/null +++ b/src/content/pages/config.ts @@ -0,0 +1,24 @@ +import { defineCollection, z } from "astro:content"; + +const elementsCollection = defineCollection({ + schema: z.object({ + title: z.string(), + meta_title: z.string().optional(), + description: z.string(), + draft: z.boolean().optional(), + }), +}); + +const privacyCollection = defineCollection({ + schema: z.object({ + title: z.string(), + meta_title: z.string().optional(), + description: z.string(), + draft: z.boolean().optional(), + }), +}); + +export const collections = { + elements: elementsCollection, + privacy: privacyCollection, +}; diff --git a/src/content/english/pages/elements.mdx b/src/content/pages/english/elements.mdx similarity index 100% rename from src/content/english/pages/elements.mdx rename to src/content/pages/english/elements.mdx diff --git a/src/content/english/pages/privacy-policy.md b/src/content/pages/english/privacy-policy.md similarity index 100% rename from src/content/english/pages/privacy-policy.md rename to src/content/pages/english/privacy-policy.md diff --git a/src/content/french/pages/elements.mdx b/src/content/pages/french/elements.mdx similarity index 100% rename from src/content/french/pages/elements.mdx rename to src/content/pages/french/elements.mdx diff --git a/src/content/french/pages/privacy-policy.md b/src/content/pages/french/privacy-policy.md similarity index 100% rename from src/content/french/pages/privacy-policy.md rename to src/content/pages/french/privacy-policy.md diff --git a/src/content/sections/config.ts b/src/content/sections/config.ts new file mode 100755 index 0000000..1f49900 --- /dev/null +++ b/src/content/sections/config.ts @@ -0,0 +1,28 @@ +import { z } from "zod"; + +const TestimonialSchema = z.object({ + name: z.string(), + designation: z.string(), + avatar: z.string(), + content: z.string(), +}); + +const TestimonialsSchema = z.array(TestimonialSchema); + +const CallToActionSchema = z.object({ + enable: z.boolean(), + title: z.string(), + image: z.string(), + description: z.string(), + button: z.object({ + enable: z.boolean(), + label: z.string(), + link: z.string().url(), + }), +}); + +export const collections = { + Testimonial: TestimonialSchema, + Testimonials: TestimonialsSchema, + CallToAction: CallToActionSchema, +}; diff --git a/src/content/english/sections/call-to-action.md b/src/content/sections/english/call-to-action.md similarity index 100% rename from src/content/english/sections/call-to-action.md rename to src/content/sections/english/call-to-action.md diff --git a/src/content/english/sections/testimonial.md b/src/content/sections/english/testimonial.md similarity index 100% rename from src/content/english/sections/testimonial.md rename to src/content/sections/english/testimonial.md diff --git a/src/content/french/sections/call-to-action.md b/src/content/sections/french/call-to-action.md similarity index 100% rename from src/content/french/sections/call-to-action.md rename to src/content/sections/french/call-to-action.md diff --git a/src/content/french/sections/testimonial.md b/src/content/sections/french/testimonial.md similarity index 100% rename from src/content/french/sections/testimonial.md rename to src/content/sections/french/testimonial.md diff --git a/src/layouts/components/BlogCard.astro b/src/layouts/components/BlogCard.astro index d2a8a89..eb15361 100644 --- a/src/layouts/components/BlogCard.astro +++ b/src/layouts/components/BlogCard.astro @@ -18,6 +18,11 @@ const { title, image, date, author, categories } = data.data; const lang = getLangFromUrl(Astro.url); const { read_more } = await getTranslations(lang as keyof ContentEntryMap); + +const slugParts = data.slug.split("/"); +slugParts[0] = "blog"; +const modifiedSlug = slugParts.join("/"); +data.slug = modifiedSlug; ---
diff --git a/src/layouts/components/Breadcrumbs.astro b/src/layouts/components/Breadcrumbs.astro index 077cdef..29e0448 100644 --- a/src/layouts/components/Breadcrumbs.astro +++ b/src/layouts/components/Breadcrumbs.astro @@ -11,19 +11,20 @@ if (supportedLang.includes(paths[0])) { lang = paths.shift()!; } +let baseHref = lang ? `/${lang}` : "/"; let parts = [ { label: "Home", - href: `/${lang}`, + href: baseHref, "aria-label": - Astro.url.pathname === `/${lang}` || Astro.url.pathname === `/${lang}/` + Astro.url.pathname === baseHref || Astro.url.pathname === `${baseHref}/` ? "page" : undefined, }, ]; paths.forEach((label: string, i: number) => { - const href = `/${lang}/${paths.slice(0, i + 1).join("/")}`; + const href = `${baseHref}${paths.slice(0, i + 1).join("/")}`; label !== "page" && parts.push({ label: humanize(label.replace(".html", "").replace(/[-_]/g, " ")) || "", diff --git a/src/layouts/partials/Testimonial.astro b/src/layouts/partials/Testimonial.astro index 9fb2cc5..35ca07b 100644 --- a/src/layouts/partials/Testimonial.astro +++ b/src/layouts/partials/Testimonial.astro @@ -67,7 +67,7 @@ const { testimonial } = Astro.props;
- ), + ) )}
diff --git a/src/lib/contentParser.astro b/src/lib/contentParser.astro index 4e98a64..048b5d3 100644 --- a/src/lib/contentParser.astro +++ b/src/lib/contentParser.astro @@ -9,7 +9,7 @@ import { import config from "@/config/config.json"; import languages from "@/config/language.json"; -export const getSinglePage = async ( +export const getSP = async ( collectionName: C, lang: keyof ContentEntryMap | undefined ): Promise[]> => { @@ -40,7 +40,7 @@ export const getSinglePage = async ( return removeDrafts; }; -export const getListPage = async ( +export const getLP = async ( collectionName: C, lang: keyof ContentEntryMap | undefined ): Promise[]> => { @@ -67,4 +67,68 @@ export const getListPage = async ( return pages; }; + +export const getSinglePage = async ( + collectionName: C, + lang: keyof ContentEntryMap | undefined, + subCollectionName?: string +): Promise[]> => { + const { default_language } = config.settings; + + const selectedLanguageCode = lang || default_language; + + const language = languages.find( + (l: any) => l.languageCode === selectedLanguageCode + ); + + if (!language) { + throw new Error("Language not found"); + } + + const { contentDir } = language; + + const path = subCollectionName + ? `${contentDir}/${subCollectionName}` + : contentDir; + + const pages: CollectionEntry[] = (await getCollection( + collectionName as any, + ({ id }: any) => { + return id.startsWith(path) && !id.endsWith("-index.md"); + } + )) as CollectionEntry[]; + + // @ts-ignore + const removeDrafts = pages.filter((data) => !data.data.draft); + + return removeDrafts; +}; + +export const getListPage = async ( + collectionName: C, + lang: keyof ContentEntryMap | undefined +): Promise[]> => { + const { default_language } = config.settings; + + const selectedLanguageCode = lang || default_language; + + const language = languages.find( + (l: any) => l.languageCode == selectedLanguageCode + ); + + if (!language) { + throw new Error("Language not found"); + } + + const { contentDir } = language; + + const pages: CollectionEntry[] = (await getCollection( + collectionName as any, + ({ id }: any) => { + return id.startsWith(contentDir); + } + )) as CollectionEntry[]; + + return pages; +}; --- diff --git a/src/lib/taxonomyParser.astro b/src/lib/taxonomyParser.astro index 69c0c1c..ad38fb0 100644 --- a/src/lib/taxonomyParser.astro +++ b/src/lib/taxonomyParser.astro @@ -16,7 +16,7 @@ export const getTaxonomy = async (collection: string, name: string) => { actualCollection = language.contentDir; } else { const defaultLanguageMatch = languages.find( - (l) => l.languageCode === default_language, + (l) => l.languageCode === default_language ); if (defaultLanguageMatch) { actualCollection = defaultLanguageMatch.contentDir; @@ -24,10 +24,10 @@ export const getTaxonomy = async (collection: string, name: string) => { } const singlePages = await getCollection( - actualCollection as keyof ContentEntryMap, + "blog" as keyof ContentEntryMap, ({ id }: any) => { - return id.startsWith("blog") && !id.endsWith("-index.md"); - }, + return id.startsWith(actualCollection) && !id.endsWith("-index.md"); + } ); const taxonomyPages = singlePages.map((page: any) => page.data[name]); let taxonomies: string[] = []; @@ -52,7 +52,7 @@ export const getAllTaxonomy = async (collection: string, name: string) => { actualCollection = language.contentDir; } else { const defaultLanguageMatch = languages.find( - (l) => l.languageCode === default_language, + (l) => l.languageCode === default_language ); if (defaultLanguageMatch) { actualCollection = defaultLanguageMatch.contentDir; @@ -60,10 +60,10 @@ export const getAllTaxonomy = async (collection: string, name: string) => { } const singlePages = await getCollection( - actualCollection as keyof ContentEntryMap, + "blog" as keyof ContentEntryMap, ({ id }: any) => { - return id.startsWith("blog") && !id.endsWith("-index.md"); - }, + return id.startsWith(actualCollection) && !id.endsWith("-index.md"); + } ); const taxonomyPages = singlePages.map((page: any) => page.data[name]); let taxonomies: string[] = []; diff --git a/src/pages/[...lang]/[regular].astro b/src/pages/[...lang]/[regular].astro index 6e0ebc8..cc08640 100755 --- a/src/pages/[...lang]/[regular].astro +++ b/src/pages/[...lang]/[regular].astro @@ -10,7 +10,7 @@ export async function getStaticPaths() { supportedLang.map(async (lang) => { const pages = await getSinglePage("pages", lang as keyof ContentEntryMap); - return pages.map((page: any) => ({ + return pages.map((page) => ({ params: { lang: lang || undefined, regular: page.slug.split("/").pop(), diff --git a/src/pages/[...lang]/about.astro b/src/pages/[...lang]/about.astro index c45110a..9065501 100644 --- a/src/pages/[...lang]/about.astro +++ b/src/pages/[...lang]/about.astro @@ -4,7 +4,7 @@ import Base from "@/layouts/Base.astro"; import { getListPage } from "@/lib/contentParser.astro"; import { supportedLang } from "@/lib/utils/languageParser"; import { markdownify } from "@/lib/utils/textConverter"; -import type { ContentCollectionKey, ContentEntryMap } from "astro:content"; +import type { ContentEntryMap } from "astro:content"; export function getStaticPaths() { const paths = supportedLang.map((lang) => ({ @@ -14,10 +14,7 @@ export function getStaticPaths() { } const { lang } = Astro.params; -const about: any = await getListPage( - "about" as ContentCollectionKey, - lang as keyof ContentEntryMap -); +const about = await getListPage("about", lang as keyof ContentEntryMap); const { Content } = await about[0].render(); const { title, description, meta_title, image } = about[0].data; diff --git a/src/pages/[...lang]/authors/[single].astro b/src/pages/[...lang]/authors/[single].astro index afdf6ae..e50b1ee 100755 --- a/src/pages/[...lang]/authors/[single].astro +++ b/src/pages/[...lang]/authors/[single].astro @@ -14,12 +14,12 @@ export async function getStaticPaths() { const paths = await Promise.all( supportedLang.map(async (lang) => { - const authors: any = await getSinglePage( + const authors = await getSinglePage( COLLECTION_FOLDER, lang as keyof ContentEntryMap ); - return authors.map((author: any) => ({ + return authors.map((author) => ({ params: { lang: lang || undefined, single: author.slug.split("/").pop(), @@ -42,7 +42,7 @@ const { Content } = await author.render(); const BLOG_FOLDER = "blog"; const posts = await getSinglePage(BLOG_FOLDER, lang as keyof ContentEntryMap); const postFilterByAuthor = posts.filter( - (post: any) => slugify(post.data.author) === slugify(title) + (post) => slugify(post.data.author) === slugify(title) ); --- diff --git a/src/pages/[...lang]/authors/index.astro b/src/pages/[...lang]/authors/index.astro index 902e6fa..e0f1e8d 100755 --- a/src/pages/[...lang]/authors/index.astro +++ b/src/pages/[...lang]/authors/index.astro @@ -16,7 +16,7 @@ export function getStaticPaths() { } const { lang } = Astro.params; -const authorIndex: any = await getListPage( +const authorIndex = await getListPage( COLLECTION_FOLDER, lang as keyof ContentEntryMap ); diff --git a/src/pages/[...lang]/blog/[single].astro b/src/pages/[...lang]/blog/[single].astro index f28de60..8cfa906 100755 --- a/src/pages/[...lang]/blog/[single].astro +++ b/src/pages/[...lang]/blog/[single].astro @@ -10,12 +10,12 @@ export async function getStaticPaths() { const paths = await Promise.all( supportedLang.map(async (lang) => { - const posts: any = await getSinglePage( + const posts = await getSinglePage( BLOG_FOLDER, lang as keyof ContentEntryMap ); - return posts.map((post: any) => ({ + return posts.map((post) => ({ params: { lang: lang || undefined, single: post.slug.split("/").pop(), diff --git a/src/pages/[...lang]/blog/index.astro b/src/pages/[...lang]/blog/index.astro index 9147c46..c4f44a9 100755 --- a/src/pages/[...lang]/blog/index.astro +++ b/src/pages/[...lang]/blog/index.astro @@ -19,7 +19,7 @@ export function getStaticPaths() { } const { lang } = Astro.params; const BLOG_FOLDER = "blog"; -const postIndex: any = await getListPage( +const postIndex = await getListPage( BLOG_FOLDER, lang as keyof ContentEntryMap ); diff --git a/src/pages/[...lang]/contact.astro b/src/pages/[...lang]/contact.astro index f367848..9534843 100644 --- a/src/pages/[...lang]/contact.astro +++ b/src/pages/[...lang]/contact.astro @@ -4,7 +4,6 @@ import Base from "@/layouts/Base.astro"; import { getListPage } from "@/lib/contentParser.astro"; import { getTranslations, supportedLang } from "@/lib/utils/languageParser"; import PageHeader from "@/partials/PageHeader.astro"; -import type { CollectionKey } from "astro:content"; import { type ContentEntryMap } from "astro:content"; export function getStaticPaths() { @@ -15,10 +14,7 @@ export function getStaticPaths() { } const { lang } = Astro.params; -const contact: any = await getListPage( - "contact" as CollectionKey, - lang as keyof ContentEntryMap -); +const contact = await getListPage("contact", lang as keyof ContentEntryMap); const { contact_form_action }: { contact_form_action: string } = config.params; const { title, description, meta_title, image } = contact[0].data; diff --git a/src/pages/[...lang]/index.astro b/src/pages/[...lang]/index.astro index d0bd1bf..a4aae5f 100755 --- a/src/pages/[...lang]/index.astro +++ b/src/pages/[...lang]/index.astro @@ -6,18 +6,9 @@ import { supportedLang } from "@/lib/utils/languageParser"; 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 { ContentCollectionKey, ContentEntryMap } from "astro:content"; +import type { Feature } from "@/types"; +import type { ContentEntryMap } from "astro:content"; import { FaCheck } from "react-icons/fa"; -interface Homepage { - banner: { - title: string; - content: string; - image: string; - button: Button; - }; - features: Feature[]; -} export function getStaticPaths() { const paths = supportedLang.map((lang) => ({ @@ -27,20 +18,19 @@ export function getStaticPaths() { } const { lang } = Astro.params; -const homepage: any = await getListPage( - "homepage" as ContentCollectionKey, - lang as keyof ContentEntryMap -); -const { banner, features }: Homepage = homepage[0].data; +const homepage = await getListPage("homepage", lang as keyof ContentEntryMap); +const { banner, features } = homepage[0].data; const testimonial = await getSinglePage( - "sections/testimonial" as ContentCollectionKey, - lang as keyof ContentEntryMap + "sections", + lang as keyof ContentEntryMap, + "testimonial" ); const call_to_action = await getSinglePage( - "sections/call-to-action" as ContentCollectionKey, - lang as keyof ContentEntryMap + "sections", + lang as keyof ContentEntryMap, + "call-to-action" ); --- From e33a7dddcfca1062f00a054a7afc51b131632824 Mon Sep 17 00:00:00 2001 From: Al Murad Uzzaman Date: Thu, 23 May 2024 16:16:41 +0600 Subject: [PATCH 3/7] zod schema modified --- src/content/about/config.ts | 11 ----- src/content/authors/config.ts | 29 ----------- src/content/blog/config.ts | 33 ------------- src/content/config.ts | 89 +++++++++++++++++++++++++++++++++- src/content/contact/config.ts | 14 ------ src/content/homepage/config.ts | 42 ---------------- src/content/sections/config.ts | 28 ----------- 7 files changed, 88 insertions(+), 158 deletions(-) delete mode 100755 src/content/about/config.ts delete mode 100755 src/content/authors/config.ts delete mode 100755 src/content/blog/config.ts delete mode 100755 src/content/contact/config.ts delete mode 100755 src/content/homepage/config.ts delete mode 100755 src/content/sections/config.ts diff --git a/src/content/about/config.ts b/src/content/about/config.ts deleted file mode 100755 index 71ddbf1..0000000 --- a/src/content/about/config.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { z } from "zod"; - -const AboutSchema = z.object({ - title: z.string(), - meta_title: z.string().optional(), - description: z.string().optional(), - image: z.string(), - draft: z.boolean().optional(), -}); - -export default AboutSchema; diff --git a/src/content/authors/config.ts b/src/content/authors/config.ts deleted file mode 100755 index d0eb2e1..0000000 --- a/src/content/authors/config.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { defineCollection, z } from "astro:content"; - -// 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(), - }), -}); - -// Export collections -export const collections = { - authors: authorsCollection, -}; diff --git a/src/content/blog/config.ts b/src/content/blog/config.ts deleted file mode 100755 index e2f906b..0000000 --- a/src/content/blog/config.ts +++ /dev/null @@ -1,33 +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(), - }), -}); - -// 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, - pages: pagesCollection, -}; diff --git a/src/content/config.ts b/src/content/config.ts index 6b926a5..c690a41 100755 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -1,6 +1,6 @@ import { defineCollection, z } from "astro:content"; -// Post collection schema +// Blog collection schema const blogCollection = defineCollection({ schema: z.object({ title: z.string(), @@ -49,9 +49,96 @@ const pagesCollection = defineCollection({ }), }); +// Contact collection schema +const contactCollection = defineCollection({ + schema: z.object({ + title: z.string(), + meta_title: z.string().optional(), + description: z.string(), + image: z.string().optional(), + draft: z.boolean().optional(), + }), +}); + +// About collection schema +const aboutCollection = defineCollection({ + schema: z.object({ + title: z.string(), + meta_title: z.string().optional(), + description: z.string().optional(), + image: z.string(), + draft: z.boolean().optional(), + }), +}); + +// Banner schema +const bannerSchema = z.object({ + title: z.string(), + content: z.string(), + image: z.string(), + button: z.object({ + enable: z.boolean(), + label: z.string(), + link: z.string(), + }), +}); + +// Features schema +const featureSchema = 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().optional(), + link: z.string().optional(), + }), +}); + +// Content schema (for the main content structure with banner and features) +const contentSchema = z.object({ + banner: bannerSchema, + features: z.array(featureSchema), +}); + +// Content collection schema +const contentCollection = defineCollection({ + schema: contentSchema, +}); + +// Testimonial schema +const testimonialSchema = z.object({ + name: z.string(), + designation: z.string(), + avatar: z.string(), + content: z.string(), +}); + +// Testimonials schema +const testimonialsSchema = z.array(testimonialSchema); + +// Call to Action schema +const callToActionSchema = z.object({ + enable: z.boolean(), + title: z.string(), + image: z.string(), + description: z.string(), + button: z.object({ + enable: z.boolean(), + label: z.string(), + link: z.string().url(), + }), +}); + // Export collections export const collections = { blog: blogCollection, authors: authorsCollection, pages: pagesCollection, + contact: contactCollection, + about: aboutCollection, + content: contentCollection, + testimonials: testimonialsSchema, + callToAction: callToActionSchema, }; diff --git a/src/content/contact/config.ts b/src/content/contact/config.ts deleted file mode 100755 index 349b955..0000000 --- a/src/content/contact/config.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { defineCollection, z } from "astro:content"; - -const contactCollection = defineCollection({ - schema: z.object({ - title: z.string(), - meta_title: z.string().optional(), - description: z.string(), - draft: z.boolean().optional(), - }), -}); - -export const collections = { - contact: contactCollection, -}; diff --git a/src/content/homepage/config.ts b/src/content/homepage/config.ts deleted file mode 100755 index 0262957..0000000 --- a/src/content/homepage/config.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { defineCollection, z } from "astro:content"; - -// Banner schema -const bannerSchema = z.object({ - title: z.string(), - content: z.string(), - image: z.string(), - button: z.object({ - enable: z.boolean(), - label: z.string(), - link: z.string(), - }), -}); - -// Features schema -const featureSchema = 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().optional(), - link: z.string().optional(), - }), -}); - -// Main content schema -const contentSchema = z.object({ - banner: bannerSchema, - features: z.array(featureSchema), -}); - -// Define the collection -const contentCollection = defineCollection({ - schema: contentSchema, -}); - -// Export collections -export const collections = { - content: contentCollection, -}; diff --git a/src/content/sections/config.ts b/src/content/sections/config.ts deleted file mode 100755 index 1f49900..0000000 --- a/src/content/sections/config.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { z } from "zod"; - -const TestimonialSchema = z.object({ - name: z.string(), - designation: z.string(), - avatar: z.string(), - content: z.string(), -}); - -const TestimonialsSchema = z.array(TestimonialSchema); - -const CallToActionSchema = z.object({ - enable: z.boolean(), - title: z.string(), - image: z.string(), - description: z.string(), - button: z.object({ - enable: z.boolean(), - label: z.string(), - link: z.string().url(), - }), -}); - -export const collections = { - Testimonial: TestimonialSchema, - Testimonials: TestimonialsSchema, - CallToAction: CallToActionSchema, -}; From b01e1a8e069797601f4f5882acbb0ec171f77f54 Mon Sep 17 00:00:00 2001 From: Al Murad Uzzaman Date: Mon, 27 May 2024 11:31:07 +0600 Subject: [PATCH 4/7] jsonGenerator Fixed --- scripts/jsonGenerator.js | 29 ++++++++++++++++------------ src/config/config.json | 2 +- src/layouts/Base.astro | 15 ++++++++------ src/layouts/helpers/SearchModal.tsx | 18 ++++++++++++++--- src/layouts/helpers/SearchResult.tsx | 16 +++++++++++---- 5 files changed, 54 insertions(+), 26 deletions(-) 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 } =
- +
diff --git a/src/layouts/helpers/SearchModal.tsx b/src/layouts/helpers/SearchModal.tsx index 6d29287..f095d7f 100644 --- a/src/layouts/helpers/SearchModal.tsx +++ b/src/layouts/helpers/SearchModal.tsx @@ -1,8 +1,11 @@ import searchData from ".json/search.json"; import React, { useEffect, useState } from "react"; import SearchResult, { type ISearchItem } from "./SearchResult"; +import config from "@/config/config.json"; +const { default_language } = config.settings; -const SearchModal = () => { +const SearchModal = ({ lang }: { lang: string | undefined }) => { + lang = lang || default_language; const [searchString, setSearchString] = useState(""); // handle input change @@ -39,9 +42,13 @@ const SearchModal = () => { } }; + // filter language specific search data + const filterSearchData = searchData.filter((item) => item.lang === lang); + + // get search result const startTime = performance.now(); - const searchResult = doSearch(searchData); + const searchResult = doSearch(filterSearchData); const endTime = performance.now(); const totalTime = ((endTime - startTime) / 1000).toFixed(3); @@ -169,10 +176,15 @@ const SearchModal = () => { name="search" value={searchString} onChange={handleSearch} + autoFocus autoComplete="off" />
- +
diff --git a/src/layouts/helpers/SearchResult.tsx b/src/layouts/helpers/SearchResult.tsx index 6c0efae..810cc3c 100755 --- a/src/layouts/helpers/SearchResult.tsx +++ b/src/layouts/helpers/SearchResult.tsx @@ -1,7 +1,9 @@ +import { slugSelector } from "@/lib/utils/languageParser"; import { plainify, titleify } from "@/lib/utils/textConverter"; import React from "react"; export interface ISearchItem { + lang: string; group: string; slug: string; frontmatter: { @@ -33,10 +35,13 @@ export interface ISearchGroup { const SearchResult = ({ searchResult, searchString, + lang }: { searchResult: ISearchItem[]; searchString: string; + lang: string; }) => { + // generate search result group const generateSearchGroup = (searchResult: ISearchItem[]) => { const joinDataByGroup: ISearchGroup[] = searchResult.reduce( @@ -83,6 +88,7 @@ const SearchResult = ({ ); }; + // match underline const matchUnderline = (text: string, substring: string) => { const parts = text?.split(new RegExp(`(${substring})`, "gi")); @@ -148,12 +154,14 @@ const SearchResult = ({ {item.frontmatter.title}
)} From f4c45c5b8fa67fc16cf57b88c1e9a3c0477bbfe6 Mon Sep 17 00:00:00 2001 From: Al Murad Uzzaman Date: Wed, 31 Jul 2024 12:17:20 +0600 Subject: [PATCH 5/7] readme modified --- package.json | 52 ++++++++++++------------ readme.md | 7 +++- src/config/config.json | 2 +- src/content/pages/config.ts | 24 ----------- src/layouts/helpers/LanguageSwitcher.tsx | 7 ++-- src/layouts/partials/Header.astro | 14 ++++--- src/lib/utils/languageParser.ts | 4 +- 7 files changed, 46 insertions(+), 64 deletions(-) delete mode 100755 src/content/pages/config.ts diff --git a/package.json b/package.json index 9a7cd97..2581fc6 100755 --- a/package.json +++ b/package.json @@ -15,47 +15,47 @@ "remove-multilang": "node scripts/removeMultilang.js && yarn format" }, "dependencies": { - "@astrojs/mdx": "^2.3.0", - "@astrojs/react": "^3.3.0", - "@astrojs/rss": "^4.0.5", - "@astrojs/sitemap": "^3.1.2", + "@astrojs/mdx": "^3.1.3", + "@astrojs/react": "^3.6.1", + "@astrojs/rss": "^4.0.7", + "@astrojs/sitemap": "^3.1.6", "@astrojs/tailwind": "^5.1.0", - "astro": "^4.6.1", + "astro": "^4.12.3", "astro-auto-import": "^0.4.2", - "astro-font": "^0.0.80", + "astro-font": "^0.0.81", "date-fns": "^3.6.0", "disqus-react": "^1.1.5", "github-slugger": "^2.0.0", "gray-matter": "^4.0.3", - "marked": "^12.0.1", - "prettier-plugin-astro": "^0.13.0", - "prettier-plugin-tailwindcss": "^0.5.13", + "marked": "^13.0.3", + "prettier-plugin-astro": "^0.14.1", + "prettier-plugin-tailwindcss": "^0.6.5", "prop-types": "^15.8.1", - "react": "^18.2.0", - "react-dom": "^18.2.0", - "react-icons": "^5.0.1", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "react-icons": "^5.2.1", "react-lite-youtube-embed": "^2.4.0", "remark-collapse": "^0.1.2", "remark-toc": "^9.0.0", - "swiper": "^11.1.1" + "swiper": "^11.1.8" }, "devDependencies": { "@tailwindcss/forms": "^0.5.7", - "@tailwindcss/typography": "^0.5.12", + "@tailwindcss/typography": "^0.5.13", "@types/marked": "^5.0.2", - "@types/node": "20.12.7", - "@types/react": "18.2.78", - "@types/react-dom": "18.2.25", + "@types/node": "22.0.0", + "@types/react": "18.3.3", + "@types/react-dom": "18.3.0", "autoprefixer": "^10.4.19", - "eslint": "^9.0.0", - "postcss": "^8.4.38", - "prettier": "^3.2.5", - "prettier-plugin-astro": "^0.13.0", - "prettier-plugin-tailwindcss": "^0.5.13", - "sass": "^1.75.0", - "sharp": "0.33.1", + "eslint": "^9.8.0", + "postcss": "^8.4.40", + "prettier": "^3.3.3", + "prettier-plugin-astro": "^0.14.1", + "prettier-plugin-tailwindcss": "^0.6.5", + "sass": "^1.77.8", + "sharp": "0.33.4", "tailwind-bootstrap-grid": "^5.1.0", - "tailwindcss": "^3.4.3", - "typescript": "5.4.5" + "tailwindcss": "^3.4.7", + "typescript": "5.5.4" } } diff --git a/readme.md b/readme.md index d098e30..ab5c00c 100755 --- a/readme.md +++ b/readme.md @@ -26,6 +26,7 @@ ## 📌 Key Features - 👥 Multi-Authors +- 🌐 Multilingual - 🎯 Similar Posts Suggestion - 🔍 Search Functionality - 🌑 Dark Mode @@ -65,10 +66,10 @@ ### 📦 Dependencies -- astro 4.0+ +- astro v4.12+ - node v20.10+ - npm v10.2+ -- tailwind v3.3+ +- tailwind v3.4+ ### 👉 Install Dependencies @@ -109,12 +110,14 @@ docker run -it --rm astroplate ash ``` + ## 🐞 Reporting Issues We use GitHub Issues as the official bug tracker for this Template. Please Search [existing issues](https://github.com/zeon-studio/astroplate/issues). It’s possible someone has already reported the same problem. If your problem or idea has not been addressed yet, feel free to [open a new issue](https://github.com/zeon-studio/astroplate/issues). + ## 📝 License Copyright (c) 2023 - Present, Designed & Developed by [Zeon Studio](https://zeon.studio/) diff --git a/src/config/config.json b/src/config/config.json index 83920f1..834fbf1 100755 --- a/src/config/config.json +++ b/src/config/config.json @@ -22,7 +22,7 @@ "blog_folder": "blog", "default_language": "en", "disable_languages": [], - "default_language_in_path": false + "default_language_in_subdir": true }, "params": { diff --git a/src/content/pages/config.ts b/src/content/pages/config.ts deleted file mode 100755 index b159fc5..0000000 --- a/src/content/pages/config.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { defineCollection, z } from "astro:content"; - -const elementsCollection = defineCollection({ - schema: z.object({ - title: z.string(), - meta_title: z.string().optional(), - description: z.string(), - draft: z.boolean().optional(), - }), -}); - -const privacyCollection = defineCollection({ - schema: z.object({ - title: z.string(), - meta_title: z.string().optional(), - description: z.string(), - draft: z.boolean().optional(), - }), -}); - -export const collections = { - elements: elementsCollection, - privacy: privacyCollection, -}; diff --git a/src/layouts/helpers/LanguageSwitcher.tsx b/src/layouts/helpers/LanguageSwitcher.tsx index feb601b..5b60f59 100644 --- a/src/layouts/helpers/LanguageSwitcher.tsx +++ b/src/layouts/helpers/LanguageSwitcher.tsx @@ -1,5 +1,5 @@ import config from "@/config/config.json"; -import languages from "@/config/language.json"; +import languages from "@/config/language.json"; `` import React from "react"; const LanguageSwitcher = ({ @@ -21,11 +21,12 @@ const LanguageSwitcher = ({ // Sort languages by weight and filter out disabled languages const sortedLanguages = languages + // @ts-ignore .filter(language => !config.settings.disable_languages.includes(language.languageCode)) .sort((a, b) => a.weight - b.weight); return ( -
+
1 ? "block" : "hidden"}`}>