diff --git a/__mocks__/data/mock-post.ts b/__mocks__/data/mock-post.ts index 07083a46..bdfbcc25 100644 --- a/__mocks__/data/mock-post.ts +++ b/__mocks__/data/mock-post.ts @@ -19,9 +19,6 @@ export const MockPost: ExtendedPostInfo = { headingsWithId: [], wordCount: 10000, contentMeta: "", - translations: { - en: "English", - }, Content: {} as never, suggestedArticles: [] as never, attached: [], @@ -47,9 +44,6 @@ export const MockMultiAuthorPost: ExtendedPostInfo = { headingsWithId: [], wordCount: 100000, contentMeta: "", - translations: { - en: "English", - }, Content: {} as never, suggestedArticles: [] as never, attached: [], @@ -75,9 +69,6 @@ export const MockMuliLanguagePost: ExtendedPostInfo = { headingsWithId: [], wordCount: 100000, contentMeta: "", - translations: { - es: "EspaƱol", - }, Content: {} as never, suggestedArticles: [] as never, attached: [], @@ -104,9 +95,6 @@ export const MockCanonicalPost: ExtendedPostInfo = { headingsWithId: [], wordCount: 100000, contentMeta: "", - translations: { - en: "English", - }, Content: {} as never, suggestedArticles: [] as never, attached: [], diff --git a/build-scripts/generate-epubs.ts b/build-scripts/generate-epubs.ts index e7e64b2c..83670ead 100644 --- a/build-scripts/generate-epubs.ts +++ b/build-scripts/generate-epubs.ts @@ -217,7 +217,7 @@ const posts = [...getAllExtendedPosts("en")]; for (const collection of collections) { const collectionPosts = posts.filter( - (post) => post.series === collection.slug + (post) => post.collection === collection.slug ); generateCollectionEPub( diff --git a/content/blog/basic-overview-of-packets-and-osi/index.md b/content/blog/basic-overview-of-packets-and-osi/index.md index 898ee01c..92b65100 100644 --- a/content/blog/basic-overview-of-packets-and-osi/index.md +++ b/content/blog/basic-overview-of-packets-and-osi/index.md @@ -7,7 +7,7 @@ tags: ['networking'], attached: [], license: 'cc-by-nc-sa-4', - series: "Networking 101", + collection: "Networking 101", order: 1 } --- diff --git a/content/blog/intro-to-web-components-vanilla-js/index.md b/content/blog/intro-to-web-components-vanilla-js/index.md index 34f9fb37..40d44d67 100644 --- a/content/blog/intro-to-web-components-vanilla-js/index.md +++ b/content/blog/intro-to-web-components-vanilla-js/index.md @@ -8,7 +8,7 @@ attached: [], license: 'coderpad', originalLink: 'https://coderpad.io/blog/intro-to-web-components-vanilla-js/', - series: "web-components-101", + collection: "web-components-101", order: 2 } --- diff --git a/content/blog/javascript-functions-are-values/index.md b/content/blog/javascript-functions-are-values/index.md index 23f9b322..82539b80 100644 --- a/content/blog/javascript-functions-are-values/index.md +++ b/content/blog/javascript-functions-are-values/index.md @@ -8,7 +8,7 @@ attached: [], license: 'coderpad', originalLink: 'https://coderpad.io/blog/development/what-you-never-learned-about-javascript-functions/', - series: "JavaScript Fundamentals", + collection: "JavaScript Fundamentals", order: 1 } --- diff --git a/content/blog/minecraft-data-packs-cmd-syntax/index.md b/content/blog/minecraft-data-packs-cmd-syntax/index.md index 1db6f567..8b1913a5 100644 --- a/content/blog/minecraft-data-packs-cmd-syntax/index.md +++ b/content/blog/minecraft-data-packs-cmd-syntax/index.md @@ -7,7 +7,7 @@ tags: [], attached: [], license: 'cc-by-nc-sa-4', - series: "minecraft-data-packs", + collection: "minecraft-data-packs", order: 2 } --- diff --git a/content/blog/minecraft-data-packs-introduction/index.md b/content/blog/minecraft-data-packs-introduction/index.md index d4ff6996..992583df 100644 --- a/content/blog/minecraft-data-packs-introduction/index.md +++ b/content/blog/minecraft-data-packs-introduction/index.md @@ -7,7 +7,7 @@ tags: [], attached: [], license: 'cc-by-nc-sa-4', - series: "minecraft-data-packs", + collection: "minecraft-data-packs", order: 1 } --- diff --git a/content/blog/minecraft-data-packs-scoreboards/index.md b/content/blog/minecraft-data-packs-scoreboards/index.md index 9846a14b..72023020 100644 --- a/content/blog/minecraft-data-packs-scoreboards/index.md +++ b/content/blog/minecraft-data-packs-scoreboards/index.md @@ -7,7 +7,7 @@ tags: [], attached: [], license: 'cc-by-nc-sa-4', - series: "minecraft-data-packs", + collection: "minecraft-data-packs", order: 3 } --- diff --git a/content/blog/networking-101-udp-and-tcp/index.md b/content/blog/networking-101-udp-and-tcp/index.md index e152ea40..dc76ab48 100644 --- a/content/blog/networking-101-udp-and-tcp/index.md +++ b/content/blog/networking-101-udp-and-tcp/index.md @@ -7,7 +7,7 @@ tags: ['networking'], attached: [], license: 'cc-by-nc-sa-4', - series: "Networking 101", + collection: "Networking 101", order: 2 } --- diff --git a/content/blog/web-components-101-framework-comparison/index.md b/content/blog/web-components-101-framework-comparison/index.md index 2837c2af..02f4de52 100644 --- a/content/blog/web-components-101-framework-comparison/index.md +++ b/content/blog/web-components-101-framework-comparison/index.md @@ -8,7 +8,7 @@ attached: [], license: 'coderpad', originalLink: 'https://coderpad.io/blog/web-components-101-framework-comparison/', - series: "web-components-101", + collection: "web-components-101", order: 4 } --- diff --git a/content/blog/web-components-101-history/index.md b/content/blog/web-components-101-history/index.md index 2c52fa07..b6c24764 100644 --- a/content/blog/web-components-101-history/index.md +++ b/content/blog/web-components-101-history/index.md @@ -8,7 +8,7 @@ attached: [], license: 'coderpad', originalLink: 'https://coderpad.io/blog/web-components-101-history/', - series: "web-components-101", + collection: "web-components-101", order: 1 } --- diff --git a/content/blog/web-components-101-lit-framework/index.md b/content/blog/web-components-101-lit-framework/index.md index c6409b0f..b7702417 100644 --- a/content/blog/web-components-101-lit-framework/index.md +++ b/content/blog/web-components-101-lit-framework/index.md @@ -8,7 +8,7 @@ attached: [], license: 'coderpad', originalLink: 'https://coderpad.io/blog/web-components-101-lit-framework/', - series: "web-components-101", + collection: "web-components-101", order: 3 } --- diff --git a/content/blog/what-are-uuids/index.md b/content/blog/what-are-uuids/index.md index 57b920c8..af39a1e2 100644 --- a/content/blog/what-are-uuids/index.md +++ b/content/blog/what-are-uuids/index.md @@ -7,7 +7,7 @@ tags: ['computer science'], attached: [], license: 'cc-by-4', - series: "Explaining UUIDs", + collection: "Explaining UUIDs", order: 1 } --- diff --git a/content/blog/what-happened-to-uuid-v2/index.md b/content/blog/what-happened-to-uuid-v2/index.md index 2436d38d..c28e2da4 100644 --- a/content/blog/what-happened-to-uuid-v2/index.md +++ b/content/blog/what-happened-to-uuid-v2/index.md @@ -7,7 +7,7 @@ tags: ['computer science'], attached: [], license: 'cc-by-4', - series: "Explaining UUIDs", + collection: "Explaining UUIDs", order: 2 } --- diff --git a/src/components/collection-card/collection-card.astro b/src/components/collection-card/collection-card.astro index 4e5f9b0e..4072e35c 100644 --- a/src/components/collection-card/collection-card.astro +++ b/src/components/collection-card/collection-card.astro @@ -9,7 +9,7 @@ import { Picture } from "@astrojs/image/components"; import { getFullRelativePath } from "utils/url-paths"; import { ExtendedCollectionInfo } from "types/index"; import { translate } from "utils/translations"; -import { getPostsBySeries } from "utils/api"; +import { getPostsByCollection } from "utils/api"; type CollectionCardProps = { collection: Pick< @@ -32,7 +32,7 @@ const coverImgPath = getFullRelativePath( collection.coverImg ); -const collectionPosts = getPostsBySeries(collection.slug, "en"); +const collectionPosts = getPostsByCollection(collection.slug, "en"); --- diff --git a/src/pages/[locale]/posts/[postid].astro b/src/pages/[locale]/posts/[postid].astro index a3ee5dee..c5e49a60 100644 --- a/src/pages/[locale]/posts/[postid].astro +++ b/src/pages/[locale]/posts/[postid].astro @@ -39,11 +39,9 @@ const { Content, post, posts, locale } = Astro.props as { Content: MarkdownInstance["Content"]; }; -const translations = post?.translations || []; +const locales = post?.locales || []; -const otherLangs = translations - ? (Object.keys(translations).filter((t) => t !== post.locale) as Languages[]) - : []; +const otherLangs = locales ? locales.filter((t) => t !== post.locale) : []; --- diff --git a/src/pages/collections/[slug].astro b/src/pages/collections/[slug].astro index 91f09f06..bec76d13 100644 --- a/src/pages/collections/[slug].astro +++ b/src/pages/collections/[slug].astro @@ -12,7 +12,7 @@ import CollectionHeaderDefault from "src/page-components/collections/collection- import CollectionTableOfContents from "src/page-components/collections/collection-table-of-contents.astro"; import { ExtendedCollectionInfo } from "types/CollectionInfo"; import { MarkdownInstance } from "astro"; -import { getPostsBySeries } from "utils/api"; +import { getPostsByCollection } from "utils/api"; export async function getStaticPaths() { const collections = await Astro.glob( @@ -42,7 +42,7 @@ const { Content, collection } = Astro.props as CollectionProps; const { slug } = collection; // TODO: support localization -const collectionPosts = getPostsBySeries(slug, "en"); +const collectionPosts = getPostsByCollection(slug, "en"); const coverImgPath = getFullRelativePath( "/content/collections", diff --git a/src/pages/posts/[postid].astro b/src/pages/posts/[postid].astro index d1cafe5e..4c299e68 100644 --- a/src/pages/posts/[postid].astro +++ b/src/pages/posts/[postid].astro @@ -35,11 +35,9 @@ const { Content, post, posts } = Astro.props as { Content: MarkdownInstance["Content"]; }; -const translations = post?.translations || []; +const locales = post?.locales || []; -const otherLangs = translations - ? (Object.keys(translations).filter((t) => t !== post.locale) as Languages[]) - : []; +const otherLangs = locales ? locales.filter((t) => t !== post.locale) : []; --- diff --git a/src/types/PostInfo.ts b/src/types/PostInfo.ts index d6c43fd5..766f1ab3 100644 --- a/src/types/PostInfo.ts +++ b/src/types/PostInfo.ts @@ -12,7 +12,7 @@ export interface RawPostInfo { license: string; description?: string; edited?: string; - series?: string; + collection?: string; order?: number; originalLink?: string; } @@ -35,7 +35,6 @@ export interface ExtendedPostInfo extends PostInfo { Content: MarkdownInstance["Content"]; excerpt: string; wordCount: number; - translations: Partial>; suggestedArticles: [PostInfo, PostInfo, PostInfo]; headingsWithId?: Array<{ // Title value diff --git a/src/utils/api.ts b/src/utils/api.ts index 77557bb7..0d6dd8f3 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -15,11 +15,11 @@ export function getPostsByUnicorn( ); } -export function getPostsBySeries( - series: string, +export function getPostsByCollection( + collection: string, language: Languages ): PostInfo[] { return getPostsByLang(language) - .filter((post) => post.series === series) + .filter((post) => post.collection === collection) .sort((postA, postB) => (postA.order > postB.order ? 1 : -1)); } diff --git a/src/utils/data.ts b/src/utils/data.ts index e570120b..1506eefa 100644 --- a/src/utils/data.ts +++ b/src/utils/data.ts @@ -150,8 +150,8 @@ function getPosts(): Array { frontmatter.license && licensesRaw.find((l) => l.id === frontmatter.license), collectionMeta: - frontmatter.series && - collections.find((c) => c.slug === frontmatter.series), + frontmatter.collection && + collections.find((c) => c.slug === frontmatter.collection), socialImg: `/generated/${slug}.twitter-preview.jpg`, }; }); diff --git a/src/utils/get-suggested-articles.ts b/src/utils/get-suggested-articles.ts index ec18df42..74755ad5 100644 --- a/src/utils/get-suggested-articles.ts +++ b/src/utils/get-suggested-articles.ts @@ -79,7 +79,7 @@ export const getSuggestedArticles = ( // Don't return the same article if (post.slug === postNode.slug) continue; - if (!!post.series && post.series === postNode.series) { + if (!!post.collection && post.collection === postNode.collection) { const { largest, smallest } = getOrderRange([...suggestedArticles, postNode]) || {}; diff --git a/src/views/base/translations/translations-header.astro b/src/views/base/translations/translations-header.astro index 4d654655..91e3af38 100644 --- a/src/views/base/translations/translations-header.astro +++ b/src/views/base/translations/translations-header.astro @@ -1,7 +1,10 @@ --- import { Languages } from "types/index"; import { languages } from "constants/index"; -import { removePrefixLanguageFromPath } from "utils/translations"; +import { + getPrefixLanguageFromPath, + removePrefixLanguageFromPath, +} from "utils/translations"; import { CardInline } from "components/base/card/card"; import style from "./translations-header.module.scss"; import { Icon } from "astro-icon"; @@ -10,8 +13,12 @@ interface TranslationsHeaderProps { locales: Languages[]; } -const { locales } = Astro.props as TranslationsHeaderProps; +const props = Astro.props as TranslationsHeaderProps; const path = removePrefixLanguageFromPath(Astro.url.pathname); +const currentLocale = getPrefixLanguageFromPath(Astro.url.pathname); + +// exclude the current locale from displayed options +const locales = props.locales.filter((locale) => locale !== currentLocale); --- @@ -19,10 +26,10 @@ const path = removePrefixLanguageFromPath(Astro.url.pathname);

Translated by our community into:{" "} { - locales.flatMap((currLang, i, arr) => { - const href = currLang === "en" ? path : `/${currLang}${path}`; + locales.flatMap((locale, i, arr) => { + const href = locale === "en" ? path : `/${locale}${path}`; return [ - {languages[currLang]}, + {languages[locale]}, i !== arr.length - 1 ? ", " : null, ]; }) diff --git a/src/views/blog-post/blog-post.astro b/src/views/blog-post/blog-post.astro index c7fdb1f8..cb82dcac 100644 --- a/src/views/blog-post/blog-post.astro +++ b/src/views/blog-post/blog-post.astro @@ -31,12 +31,12 @@ const locale = getPrefixLanguageFromPath(Astro.url.pathname); const GHLink = `https://github.com/${siteMetadata.repoPath}/tree/master${siteMetadata.relativeToPosts}/${post.slug}/index.md`; let seriesPosts: ExtendedPostInfo[] = []; -if (post.series && post.order) { +if (post.collection && post.order) { seriesPosts = posts .filter( (filterPost) => filterPost.frontmatter.locale === locale && - filterPost.frontmatter.series === post.series + filterPost.frontmatter.collection === post.collection ) .sort( (postA, postB) => @@ -79,7 +79,7 @@ if (post.series && post.order) {

{ - post.series ? ( + post.collection ? ( + post.locales && post.locales.length > 1 ? ( + ) : null } - {post.series ? : null} + { + post.collection ? ( + + ) : null + }