From 1f3765086a1c1097c0e75178f56d6609aeac0eae Mon Sep 17 00:00:00 2001 From: TrymVei Date: Mon, 7 Oct 2024 13:15:06 +0200 Subject: [PATCH 01/10] feat: replaced default footer with carbon badge footer --- astro.config.mjs | 3 +++ src/components/Footer.astro | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 src/components/Footer.astro diff --git a/astro.config.mjs b/astro.config.mjs index 9dcf402..41e9aac 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -6,6 +6,9 @@ export default defineConfig({ integrations: [ starlight({ title: 'Klimakode', + components: { + Footer: "./src/components/footer.astro" + }, social: { github: 'https://github.com/strombraaten/climatecode', }, diff --git a/src/components/Footer.astro b/src/components/Footer.astro new file mode 100644 index 0000000..8504e3a --- /dev/null +++ b/src/components/Footer.astro @@ -0,0 +1,6 @@ +--- +--- + +
+ + From dfc4bd3b60adc9a35abbbb754efa227ccdecda03 Mon Sep 17 00:00:00 2001 From: TrymVei Date: Tue, 8 Oct 2024 14:01:15 +0200 Subject: [PATCH 02/10] feat: function for reading guides directory --- src/utils/documents.ts | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/utils/documents.ts diff --git a/src/utils/documents.ts b/src/utils/documents.ts new file mode 100644 index 0000000..a22bcd8 --- /dev/null +++ b/src/utils/documents.ts @@ -0,0 +1,58 @@ +import fs from 'fs'; +import path from "path"; + +const folderPath = "src/content/docs/guides/" +const absolutePath = path.join(process.cwd(), folderPath) + +type FileObject = { + label: string + slug: string +} + +export function getFilesInGuidesFolder(): FileObject[] { + const fileNames: FileObject[] = []; + + // Read the contents of the folder + const files = fs.readdirSync(absolutePath); + + // Iterate over each file + files.forEach((file) => { + // Get the full path of the file + const filePath = `${absolutePath}/${file}`; + + // Check if the path points to a file (not a directory) + if (fs.statSync(filePath).isFile()) { + const fileName = file.replaceAll(".md", "") + const fileToPush: FileObject = { + label: fileName.replaceAll("-", " "), + slug: "guides/" + fileName + + } + fileNames.push(fileToPush); + } + }); + + return fileNames; +} + +type PrevAndNext = { + prev: FileObject | null; + next: FileObject | null; +} + +export function getPrevAndNextPath(currentSlug: string | undefined): PrevAndNext { + const allGuidesFiles = getFilesInGuidesFolder(); + const currentIndex = allGuidesFiles.findIndex((file) => file.slug === currentSlug); + let next = null; + let prev = null; + if (allGuidesFiles[currentIndex + 1]) { + next = allGuidesFiles[currentIndex + 1]; + } + if (allGuidesFiles[currentIndex - 1]) { + prev = allGuidesFiles[currentIndex - 1]; + } + return { + next, + prev + } +} From 12b78c602fc0f66fba43571e35cf8824dc08e539 Mon Sep 17 00:00:00 2001 From: TrymVei Date: Tue, 8 Oct 2024 14:01:39 +0200 Subject: [PATCH 03/10] feat: astro config add all files from guides --- astro.config.mjs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 41e9aac..0916717 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,5 +1,6 @@ import { defineConfig } from 'astro/config'; import starlight from '@astrojs/starlight'; +import { getFilesInGuidesFolder } from './src/utils/documents'; // https://astro.build/config export default defineConfig({ @@ -15,12 +16,7 @@ export default defineConfig({ sidebar: [ { label: 'Tips for å utvikle mer bærekraftig ', - items: [ - // Each item here is one entry in the navigation menu. - { label: 'Bilder', slug: 'guides/bilder' }, - { label: 'Praktiske tips prioritet', slug: 'guides/praktiske-tips-prioritet' }, - { label: 'Praktiske tips ekstra', slug: 'guides/praktiske-tips-ekstra' }, - ], + items: getFilesInGuidesFolder() }, ], }), From 4e73eb7b32450040cf4ea2a9537274f8f6c7e0ba Mon Sep 17 00:00:00 2001 From: TrymVei Date: Tue, 8 Oct 2024 14:01:57 +0200 Subject: [PATCH 04/10] feat: updated footer to use prev and next link card --- src/components/Footer.astro | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 8504e3a..0766f0c 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -1,6 +1,30 @@ --- +import { LinkCard, CardGrid} from "@astrojs/starlight/components" +import { getPrevAndNextPath } from "../utils/documents" +const currentPath = Astro.params +const paths = getPrevAndNextPath(currentPath.slug) --- -
- +
+ + {paths.prev && } + {paths.next && } + +
+ + +
+
+ +
+ + + From 3c291e614a57e44c55ae8f3b27c4147583939308 Mon Sep 17 00:00:00 2001 From: TrymVei Date: Tue, 8 Oct 2024 14:01:57 +0200 Subject: [PATCH 05/10] feat: updated footer to use prev and next link card --- astro.config.mjs | 2 +- src/components/Footer.astro | 18 +++++------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 0916717..0129e19 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -8,7 +8,7 @@ export default defineConfig({ starlight({ title: 'Klimakode', components: { - Footer: "./src/components/footer.astro" + Footer: "./src/components/Footer.astro" }, social: { github: 'https://github.com/strombraaten/climatecode', diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 0766f0c..b09a824 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -1,17 +1,11 @@ --- -import { LinkCard, CardGrid} from "@astrojs/starlight/components" -import { getPrevAndNextPath } from "../utils/documents" -const currentPath = Astro.params -const paths = getPrevAndNextPath(currentPath.slug) +import Default from '@astrojs/starlight/components/Footer.astro'; +import type { Props } from '@astrojs/starlight/props'; --- -
- - {paths.prev && } - {paths.next && } - -
- + + +
@@ -24,7 +18,5 @@ const paths = getPrevAndNextPath(currentPath.slug) display: flex; justify-self: center; } - - From f9119233351054a1e01cf7271e10f15030bdf125 Mon Sep 17 00:00:00 2001 From: TrymVei Date: Tue, 8 Oct 2024 18:20:43 +0200 Subject: [PATCH 06/10] chore: remove unused function --- src/utils/documents.ts | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/utils/documents.ts b/src/utils/documents.ts index a22bcd8..410b646 100644 --- a/src/utils/documents.ts +++ b/src/utils/documents.ts @@ -26,7 +26,6 @@ export function getFilesInGuidesFolder(): FileObject[] { const fileToPush: FileObject = { label: fileName.replaceAll("-", " "), slug: "guides/" + fileName - } fileNames.push(fileToPush); } @@ -34,25 +33,3 @@ export function getFilesInGuidesFolder(): FileObject[] { return fileNames; } - -type PrevAndNext = { - prev: FileObject | null; - next: FileObject | null; -} - -export function getPrevAndNextPath(currentSlug: string | undefined): PrevAndNext { - const allGuidesFiles = getFilesInGuidesFolder(); - const currentIndex = allGuidesFiles.findIndex((file) => file.slug === currentSlug); - let next = null; - let prev = null; - if (allGuidesFiles[currentIndex + 1]) { - next = allGuidesFiles[currentIndex + 1]; - } - if (allGuidesFiles[currentIndex - 1]) { - prev = allGuidesFiles[currentIndex - 1]; - } - return { - next, - prev - } -} From 91bdc5dee0efb446a7ce4bf609d009f2e0befcb8 Mon Sep 17 00:00:00 2001 From: TrymVei Date: Tue, 8 Oct 2024 18:22:08 +0200 Subject: [PATCH 07/10] chore: added semicolons --- src/utils/documents.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/documents.ts b/src/utils/documents.ts index 410b646..b01a8bf 100644 --- a/src/utils/documents.ts +++ b/src/utils/documents.ts @@ -1,12 +1,12 @@ import fs from 'fs'; import path from "path"; -const folderPath = "src/content/docs/guides/" -const absolutePath = path.join(process.cwd(), folderPath) +const folderPath = "src/content/docs/guides/"; +const absolutePath = path.join(process.cwd(), folderPath); type FileObject = { - label: string - slug: string + label: string; + slug: string; } export function getFilesInGuidesFolder(): FileObject[] { @@ -22,7 +22,7 @@ export function getFilesInGuidesFolder(): FileObject[] { // Check if the path points to a file (not a directory) if (fs.statSync(filePath).isFile()) { - const fileName = file.replaceAll(".md", "") + const fileName = file.replaceAll(".md", ""); const fileToPush: FileObject = { label: fileName.replaceAll("-", " "), slug: "guides/" + fileName From fafd740f180a030ff7417eb31b9c827f6fe4d5b0 Mon Sep 17 00:00:00 2001 From: TrymVei Date: Thu, 10 Oct 2024 09:37:42 +0200 Subject: [PATCH 08/10] feat: left align badge left --- src/components/Footer.astro | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/components/Footer.astro b/src/components/Footer.astro index b09a824..be9ef60 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -1,22 +1,21 @@ --- -import Default from '@astrojs/starlight/components/Footer.astro'; -import type { Props } from '@astrojs/starlight/props'; +import Default from "@astrojs/starlight/components/Footer.astro"; +import type { Props } from "@astrojs/starlight/props"; --- -
-
- -
- +
+ - From 80f4d153bed43eeb3a307eeec64e22e2958cf280 Mon Sep 17 00:00:00 2001 From: TrymVei Date: Fri, 18 Oct 2024 10:43:04 +0200 Subject: [PATCH 09/10] feat: change theme on carbon badge --- astro.config.mjs | 10 +-- src/components/Footer.astro | 44 ++++++++-- src/content/docs/en/guides/images.md | 1 + .../nb/hosting/content-delivery-network.mdx | 6 +- src/content/i18n/nb-NO.json | 80 +++++++++---------- src/utils/documents.ts | 14 ++-- 6 files changed, 95 insertions(+), 60 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index dce1a16..20a5b18 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -7,13 +7,13 @@ export default defineConfig({ integrations: [ starlight({ title: 'Klimakode', - defaultLocale: "nb", + defaultLocale: 'nb', components: { - Footer: "./src/components/Footer.astro" + Footer: './src/components/Footer.astro', }, locales: { nb: { - label: "Norsk", + label: 'Norsk', lang: 'nb-NO', sidebar: [ { @@ -23,14 +23,14 @@ export default defineConfig({ ], }, en: { - label: "English", + label: 'English', sidebar: [ { label: 'Tips for developing more sustainably', autogenerate: { directory: 'en/guides' }, }, ], - } + }, }, social: { github: 'https://github.com/strombraaten/climatecode', diff --git a/src/components/Footer.astro b/src/components/Footer.astro index be9ef60..f21b1fb 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -1,17 +1,15 @@ --- -import Default from "@astrojs/starlight/components/Footer.astro"; -import type { Props } from "@astrojs/starlight/props"; +import Default from '@astrojs/starlight/components/Footer.astro'; +import type { Props } from '@astrojs/starlight/props'; --- -
- +
+ + + diff --git a/src/content/docs/en/guides/images.md b/src/content/docs/en/guides/images.md index 73f8166..e83c07a 100644 --- a/src/content/docs/en/guides/images.md +++ b/src/content/docs/en/guides/images.md @@ -29,6 +29,7 @@ Use modern formats like WebP for better compression and reduced data transfer: Use tools like cwebp or online converters to convert existing images to WebP format. ### Implement Lazy Loading for Images + Lazy loading only loads images when they become visible in the viewport: Description diff --git a/src/content/docs/nb/hosting/content-delivery-network.mdx b/src/content/docs/nb/hosting/content-delivery-network.mdx index 12ad702..a06fbef 100644 --- a/src/content/docs/nb/hosting/content-delivery-network.mdx +++ b/src/content/docs/nb/hosting/content-delivery-network.mdx @@ -8,5 +8,9 @@ import { Aside } from '@astrojs/starlight/components'; Content Delivery Network, eller CDN som det gjerne kalles, er en tjeneste som gjør at du kan levere innhold til brukerne med høy hastighet og stor pålitelighet. Spesielt nyttig i tilfeller hvor du har mange brukere som trenger tilgang til innholdet på samme tid, eller fra ulike deler av verden. diff --git a/src/content/i18n/nb-NO.json b/src/content/i18n/nb-NO.json index ea065c9..bda4fe2 100644 --- a/src/content/i18n/nb-NO.json +++ b/src/content/i18n/nb-NO.json @@ -1,42 +1,42 @@ { - "skipLink.label": "Hopp til innhold", - "search.label": "Søk", - "search.ctrlKey": "Ctrl", - "search.cancelLabel": "Avbryt", - "search.devWarning": "Search is only available in production builds. \nTry building and previewing the site to test it out locally.", - "themeSelect.accessibleLabel": "Velg utseende", - "themeSelect.dark": "Mørk", - "themeSelect.light": "Lys", - "themeSelect.auto": "Auto", - "languageSelect.accessibleLabel": "Velg språk", - "menuButton.accessibleLabel": "Meny", - "sidebarNav.accessibleLabel": "Main", - "tableOfContents.onThisPage": "På denne siden", - "tableOfContents.overview": "Oversikt", - "i18n.untranslatedContent": "Dette innholdet er ikke tilgjengelig på ditt språk ennå.", - "page.editLink": "Rediger siden", - "page.lastUpdated": "Sist oppdatert:", - "page.previousLink": "Forrige", - "page.nextLink": "Neste", - "page.draft": "Dette innholdet er et utkast og blir ikke inkludert i produksjonsbyggingen.", - "404.text": "Ai! Den siden fant jeg ikke dessverre, men slapp av, det er ikke du som har gjort noe feil, bare vi som har litt rusk i maskineriet.", - "aside.note": "Note", - "aside.tip": "Tip", - "aside.caution": "Caution", - "aside.danger": "Danger", - "fileTree.directory": "Mappe", - "builtWithStarlight.label": "Bygget med Astro, på Starlight-fundamentet", - "expressiveCode.copyButtonCopied": "Kopiert!", - "expressiveCode.copyButtonTooltip": "Kopier til utklippstavle", - "expressiveCode.terminalWindowFallbackTitle": "Terminalen", - "pagefind.clear_search": "Tøm", - "pagefind.load_more": "Last inn flere resultater", - "pagefind.search_label": "Søk på denne nettsiden", - "pagefind.filters_label": "Filtre", - "pagefind.zero_results": "Ingen resultater for [SEARCH_TERM]", - "pagefind.many_results": "[COUNT] resultater for [SEARCH_TERM]", - "pagefind.one_result": "[COUNT] resultat for [SEARCH_TERM]", - "pagefind.alt_search": "Ingen resultater for [SEARCH_TERM]. Viser resultater for [DIFFERENT_TERM] i stedet", - "pagefind.search_suggestion": "Ingen resultater for [SEARCH_TERM]. Prøv et av følgende søk i stedet:", - "pagefind.searching": "Søker etter [SEARCH_TERM]..." + "skipLink.label": "Hopp til innhold", + "search.label": "Søk", + "search.ctrlKey": "Ctrl", + "search.cancelLabel": "Avbryt", + "search.devWarning": "Search is only available in production builds. \nTry building and previewing the site to test it out locally.", + "themeSelect.accessibleLabel": "Velg utseende", + "themeSelect.dark": "Mørk", + "themeSelect.light": "Lys", + "themeSelect.auto": "Auto", + "languageSelect.accessibleLabel": "Velg språk", + "menuButton.accessibleLabel": "Meny", + "sidebarNav.accessibleLabel": "Main", + "tableOfContents.onThisPage": "På denne siden", + "tableOfContents.overview": "Oversikt", + "i18n.untranslatedContent": "Dette innholdet er ikke tilgjengelig på ditt språk ennå.", + "page.editLink": "Rediger siden", + "page.lastUpdated": "Sist oppdatert:", + "page.previousLink": "Forrige", + "page.nextLink": "Neste", + "page.draft": "Dette innholdet er et utkast og blir ikke inkludert i produksjonsbyggingen.", + "404.text": "Ai! Den siden fant jeg ikke dessverre, men slapp av, det er ikke du som har gjort noe feil, bare vi som har litt rusk i maskineriet.", + "aside.note": "Note", + "aside.tip": "Tip", + "aside.caution": "Caution", + "aside.danger": "Danger", + "fileTree.directory": "Mappe", + "builtWithStarlight.label": "Bygget med Astro, på Starlight-fundamentet", + "expressiveCode.copyButtonCopied": "Kopiert!", + "expressiveCode.copyButtonTooltip": "Kopier til utklippstavle", + "expressiveCode.terminalWindowFallbackTitle": "Terminalen", + "pagefind.clear_search": "Tøm", + "pagefind.load_more": "Last inn flere resultater", + "pagefind.search_label": "Søk på denne nettsiden", + "pagefind.filters_label": "Filtre", + "pagefind.zero_results": "Ingen resultater for [SEARCH_TERM]", + "pagefind.many_results": "[COUNT] resultater for [SEARCH_TERM]", + "pagefind.one_result": "[COUNT] resultat for [SEARCH_TERM]", + "pagefind.alt_search": "Ingen resultater for [SEARCH_TERM]. Viser resultater for [DIFFERENT_TERM] i stedet", + "pagefind.search_suggestion": "Ingen resultater for [SEARCH_TERM]. Prøv et av følgende søk i stedet:", + "pagefind.searching": "Søker etter [SEARCH_TERM]..." } diff --git a/src/utils/documents.ts b/src/utils/documents.ts index b01a8bf..c4f10fe 100644 --- a/src/utils/documents.ts +++ b/src/utils/documents.ts @@ -1,13 +1,13 @@ import fs from 'fs'; -import path from "path"; +import path from 'path'; -const folderPath = "src/content/docs/guides/"; +const folderPath = 'src/content/docs/guides/'; const absolutePath = path.join(process.cwd(), folderPath); type FileObject = { label: string; slug: string; -} +}; export function getFilesInGuidesFolder(): FileObject[] { const fileNames: FileObject[] = []; @@ -22,11 +22,11 @@ export function getFilesInGuidesFolder(): FileObject[] { // Check if the path points to a file (not a directory) if (fs.statSync(filePath).isFile()) { - const fileName = file.replaceAll(".md", ""); + const fileName = file.replaceAll('.md', ''); const fileToPush: FileObject = { - label: fileName.replaceAll("-", " "), - slug: "guides/" + fileName - } + label: fileName.replaceAll('-', ' '), + slug: 'guides/' + fileName, + }; fileNames.push(fileToPush); } }); From e0186d49268fce06da711b990ceb4fc0607e83b7 Mon Sep 17 00:00:00 2001 From: TrymVei Date: Fri, 18 Oct 2024 11:11:55 +0200 Subject: [PATCH 10/10] feat: add is inline to badge script --- src/components/Footer.astro | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Footer.astro b/src/components/Footer.astro index f21b1fb..f08fc32 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -8,8 +8,10 @@ import type { Props } from '@astrojs/starlight/props';
- +