remove obsolete translations prop, rename series->collection for clarity

This commit is contained in:
James Fenn
2023-04-09 18:08:48 -04:00
parent 3a1fefc377
commit 686d0b73a2
26 changed files with 57 additions and 58 deletions

View File

@@ -19,9 +19,6 @@ export const MockPost: ExtendedPostInfo = {
headingsWithId: [], headingsWithId: [],
wordCount: 10000, wordCount: 10000,
contentMeta: "", contentMeta: "",
translations: {
en: "English",
},
Content: {} as never, Content: {} as never,
suggestedArticles: [] as never, suggestedArticles: [] as never,
attached: [], attached: [],
@@ -47,9 +44,6 @@ export const MockMultiAuthorPost: ExtendedPostInfo = {
headingsWithId: [], headingsWithId: [],
wordCount: 100000, wordCount: 100000,
contentMeta: "", contentMeta: "",
translations: {
en: "English",
},
Content: {} as never, Content: {} as never,
suggestedArticles: [] as never, suggestedArticles: [] as never,
attached: [], attached: [],
@@ -75,9 +69,6 @@ export const MockMuliLanguagePost: ExtendedPostInfo = {
headingsWithId: [], headingsWithId: [],
wordCount: 100000, wordCount: 100000,
contentMeta: "", contentMeta: "",
translations: {
es: "Español",
},
Content: {} as never, Content: {} as never,
suggestedArticles: [] as never, suggestedArticles: [] as never,
attached: [], attached: [],
@@ -104,9 +95,6 @@ export const MockCanonicalPost: ExtendedPostInfo = {
headingsWithId: [], headingsWithId: [],
wordCount: 100000, wordCount: 100000,
contentMeta: "", contentMeta: "",
translations: {
en: "English",
},
Content: {} as never, Content: {} as never,
suggestedArticles: [] as never, suggestedArticles: [] as never,
attached: [], attached: [],

View File

@@ -217,7 +217,7 @@ const posts = [...getAllExtendedPosts("en")];
for (const collection of collections) { for (const collection of collections) {
const collectionPosts = posts.filter( const collectionPosts = posts.filter(
(post) => post.series === collection.slug (post) => post.collection === collection.slug
); );
generateCollectionEPub( generateCollectionEPub(

View File

@@ -7,7 +7,7 @@
tags: ['networking'], tags: ['networking'],
attached: [], attached: [],
license: 'cc-by-nc-sa-4', license: 'cc-by-nc-sa-4',
series: "Networking 101", collection: "Networking 101",
order: 1 order: 1
} }
--- ---

View File

@@ -8,7 +8,7 @@
attached: [], attached: [],
license: 'coderpad', license: 'coderpad',
originalLink: 'https://coderpad.io/blog/intro-to-web-components-vanilla-js/', originalLink: 'https://coderpad.io/blog/intro-to-web-components-vanilla-js/',
series: "web-components-101", collection: "web-components-101",
order: 2 order: 2
} }
--- ---

View File

@@ -8,7 +8,7 @@
attached: [], attached: [],
license: 'coderpad', license: 'coderpad',
originalLink: 'https://coderpad.io/blog/development/what-you-never-learned-about-javascript-functions/', originalLink: 'https://coderpad.io/blog/development/what-you-never-learned-about-javascript-functions/',
series: "JavaScript Fundamentals", collection: "JavaScript Fundamentals",
order: 1 order: 1
} }
--- ---

View File

@@ -7,7 +7,7 @@
tags: [], tags: [],
attached: [], attached: [],
license: 'cc-by-nc-sa-4', license: 'cc-by-nc-sa-4',
series: "minecraft-data-packs", collection: "minecraft-data-packs",
order: 2 order: 2
} }
--- ---

View File

@@ -7,7 +7,7 @@
tags: [], tags: [],
attached: [], attached: [],
license: 'cc-by-nc-sa-4', license: 'cc-by-nc-sa-4',
series: "minecraft-data-packs", collection: "minecraft-data-packs",
order: 1 order: 1
} }
--- ---

View File

@@ -7,7 +7,7 @@
tags: [], tags: [],
attached: [], attached: [],
license: 'cc-by-nc-sa-4', license: 'cc-by-nc-sa-4',
series: "minecraft-data-packs", collection: "minecraft-data-packs",
order: 3 order: 3
} }
--- ---

View File

@@ -7,7 +7,7 @@
tags: ['networking'], tags: ['networking'],
attached: [], attached: [],
license: 'cc-by-nc-sa-4', license: 'cc-by-nc-sa-4',
series: "Networking 101", collection: "Networking 101",
order: 2 order: 2
} }
--- ---

View File

@@ -8,7 +8,7 @@
attached: [], attached: [],
license: 'coderpad', license: 'coderpad',
originalLink: 'https://coderpad.io/blog/web-components-101-framework-comparison/', originalLink: 'https://coderpad.io/blog/web-components-101-framework-comparison/',
series: "web-components-101", collection: "web-components-101",
order: 4 order: 4
} }
--- ---

View File

@@ -8,7 +8,7 @@
attached: [], attached: [],
license: 'coderpad', license: 'coderpad',
originalLink: 'https://coderpad.io/blog/web-components-101-history/', originalLink: 'https://coderpad.io/blog/web-components-101-history/',
series: "web-components-101", collection: "web-components-101",
order: 1 order: 1
} }
--- ---

View File

@@ -8,7 +8,7 @@
attached: [], attached: [],
license: 'coderpad', license: 'coderpad',
originalLink: 'https://coderpad.io/blog/web-components-101-lit-framework/', originalLink: 'https://coderpad.io/blog/web-components-101-lit-framework/',
series: "web-components-101", collection: "web-components-101",
order: 3 order: 3
} }
--- ---

View File

@@ -7,7 +7,7 @@
tags: ['computer science'], tags: ['computer science'],
attached: [], attached: [],
license: 'cc-by-4', license: 'cc-by-4',
series: "Explaining UUIDs", collection: "Explaining UUIDs",
order: 1 order: 1
} }
--- ---

View File

@@ -7,7 +7,7 @@
tags: ['computer science'], tags: ['computer science'],
attached: [], attached: [],
license: 'cc-by-4', license: 'cc-by-4',
series: "Explaining UUIDs", collection: "Explaining UUIDs",
order: 2 order: 2
} }
--- ---

View File

@@ -9,7 +9,7 @@ import { Picture } from "@astrojs/image/components";
import { getFullRelativePath } from "utils/url-paths"; import { getFullRelativePath } from "utils/url-paths";
import { ExtendedCollectionInfo } from "types/index"; import { ExtendedCollectionInfo } from "types/index";
import { translate } from "utils/translations"; import { translate } from "utils/translations";
import { getPostsBySeries } from "utils/api"; import { getPostsByCollection } from "utils/api";
type CollectionCardProps = { type CollectionCardProps = {
collection: Pick< collection: Pick<
@@ -32,7 +32,7 @@ const coverImgPath = getFullRelativePath(
collection.coverImg collection.coverImg
); );
const collectionPosts = getPostsBySeries(collection.slug, "en"); const collectionPosts = getPostsByCollection(collection.slug, "en");
--- ---
<CardSolid class={style.container}> <CardSolid class={style.container}>

View File

@@ -39,11 +39,9 @@ const { Content, post, posts, locale } = Astro.props as {
Content: MarkdownInstance<any>["Content"]; Content: MarkdownInstance<any>["Content"];
}; };
const translations = post?.translations || []; const locales = post?.locales || [];
const otherLangs = translations const otherLangs = locales ? locales.filter((t) => t !== post.locale) : [];
? (Object.keys(translations).filter((t) => t !== post.locale) as Languages[])
: [];
--- ---
<Document lang={locale}> <Document lang={locale}>

View File

@@ -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 CollectionTableOfContents from "src/page-components/collections/collection-table-of-contents.astro";
import { ExtendedCollectionInfo } from "types/CollectionInfo"; import { ExtendedCollectionInfo } from "types/CollectionInfo";
import { MarkdownInstance } from "astro"; import { MarkdownInstance } from "astro";
import { getPostsBySeries } from "utils/api"; import { getPostsByCollection } from "utils/api";
export async function getStaticPaths() { export async function getStaticPaths() {
const collections = await Astro.glob( const collections = await Astro.glob(
@@ -42,7 +42,7 @@ const { Content, collection } = Astro.props as CollectionProps;
const { slug } = collection; const { slug } = collection;
// TODO: support localization // TODO: support localization
const collectionPosts = getPostsBySeries(slug, "en"); const collectionPosts = getPostsByCollection(slug, "en");
const coverImgPath = getFullRelativePath( const coverImgPath = getFullRelativePath(
"/content/collections", "/content/collections",

View File

@@ -35,11 +35,9 @@ const { Content, post, posts } = Astro.props as {
Content: MarkdownInstance<any>["Content"]; Content: MarkdownInstance<any>["Content"];
}; };
const translations = post?.translations || []; const locales = post?.locales || [];
const otherLangs = translations const otherLangs = locales ? locales.filter((t) => t !== post.locale) : [];
? (Object.keys(translations).filter((t) => t !== post.locale) as Languages[])
: [];
--- ---
<Document> <Document>

View File

@@ -12,7 +12,7 @@ export interface RawPostInfo {
license: string; license: string;
description?: string; description?: string;
edited?: string; edited?: string;
series?: string; collection?: string;
order?: number; order?: number;
originalLink?: string; originalLink?: string;
} }
@@ -35,7 +35,6 @@ export interface ExtendedPostInfo extends PostInfo {
Content: MarkdownInstance<never>["Content"]; Content: MarkdownInstance<never>["Content"];
excerpt: string; excerpt: string;
wordCount: number; wordCount: number;
translations: Partial<Record<Languages, string>>;
suggestedArticles: [PostInfo, PostInfo, PostInfo]; suggestedArticles: [PostInfo, PostInfo, PostInfo];
headingsWithId?: Array<{ headingsWithId?: Array<{
// Title value // Title value

View File

@@ -15,11 +15,11 @@ export function getPostsByUnicorn(
); );
} }
export function getPostsBySeries( export function getPostsByCollection(
series: string, collection: string,
language: Languages language: Languages
): PostInfo[] { ): PostInfo[] {
return getPostsByLang(language) return getPostsByLang(language)
.filter((post) => post.series === series) .filter((post) => post.collection === collection)
.sort((postA, postB) => (postA.order > postB.order ? 1 : -1)); .sort((postA, postB) => (postA.order > postB.order ? 1 : -1));
} }

View File

@@ -150,8 +150,8 @@ function getPosts(): Array<PostInfo> {
frontmatter.license && frontmatter.license &&
licensesRaw.find((l) => l.id === frontmatter.license), licensesRaw.find((l) => l.id === frontmatter.license),
collectionMeta: collectionMeta:
frontmatter.series && frontmatter.collection &&
collections.find((c) => c.slug === frontmatter.series), collections.find((c) => c.slug === frontmatter.collection),
socialImg: `/generated/${slug}.twitter-preview.jpg`, socialImg: `/generated/${slug}.twitter-preview.jpg`,
}; };
}); });

View File

@@ -79,7 +79,7 @@ export const getSuggestedArticles = (
// Don't return the same article // Don't return the same article
if (post.slug === postNode.slug) continue; if (post.slug === postNode.slug) continue;
if (!!post.series && post.series === postNode.series) { if (!!post.collection && post.collection === postNode.collection) {
const { largest, smallest } = const { largest, smallest } =
getOrderRange([...suggestedArticles, postNode]) || {}; getOrderRange([...suggestedArticles, postNode]) || {};

View File

@@ -1,7 +1,10 @@
--- ---
import { Languages } from "types/index"; import { Languages } from "types/index";
import { languages } from "constants/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 { CardInline } from "components/base/card/card";
import style from "./translations-header.module.scss"; import style from "./translations-header.module.scss";
import { Icon } from "astro-icon"; import { Icon } from "astro-icon";
@@ -10,8 +13,12 @@ interface TranslationsHeaderProps {
locales: Languages[]; locales: Languages[];
} }
const { locales } = Astro.props as TranslationsHeaderProps; const props = Astro.props as TranslationsHeaderProps;
const path = removePrefixLanguageFromPath(Astro.url.pathname); 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);
--- ---
<CardInline class="d-flex" size="m"> <CardInline class="d-flex" size="m">
@@ -19,10 +26,10 @@ const path = removePrefixLanguageFromPath(Astro.url.pathname);
<p class={style.text}> <p class={style.text}>
Translated by our community into:{" "} Translated by our community into:{" "}
{ {
locales.flatMap((currLang, i, arr) => { locales.flatMap((locale, i, arr) => {
const href = currLang === "en" ? path : `/${currLang}${path}`; const href = locale === "en" ? path : `/${locale}${path}`;
return [ return [
<a href={href}>{languages[currLang]}</a>, <a href={href}>{languages[locale]}</a>,
i !== arr.length - 1 ? ", " : null, i !== arr.length - 1 ? ", " : null,
]; ];
}) })

View File

@@ -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`; const GHLink = `https://github.com/${siteMetadata.repoPath}/tree/master${siteMetadata.relativeToPosts}/${post.slug}/index.md`;
let seriesPosts: ExtendedPostInfo[] = []; let seriesPosts: ExtendedPostInfo[] = [];
if (post.series && post.order) { if (post.collection && post.order) {
seriesPosts = posts seriesPosts = posts
.filter( .filter(
(filterPost) => (filterPost) =>
filterPost.frontmatter.locale === locale && filterPost.frontmatter.locale === locale &&
filterPost.frontmatter.series === post.series filterPost.frontmatter.collection === post.collection
) )
.sort( .sort(
(postA, postB) => (postA, postB) =>
@@ -79,7 +79,7 @@ if (post.series && post.order) {
</header> </header>
<main class="post-body" data-testid={"post-body-div"}> <main class="post-body" data-testid={"post-body-div"}>
{ {
post.series ? ( post.collection ? (
<SeriesToC <SeriesToC
post={post} post={post}
postSeries={seriesPosts} postSeries={seriesPosts}
@@ -88,12 +88,16 @@ if (post.series && post.order) {
) : null ) : null
} }
{ {
post.translations && Object.keys(post.translations).length ? ( post.locales && post.locales.length > 1 ? (
<TranslationsHeader locales={Object.keys(post.translations)} /> <TranslationsHeader locales={post.locales} />
) : null ) : null
} }
<Content /> <Content />
{post.series ? <SeriesNav post={post} postSeries={seriesPosts} /> : null} {
post.collection ? (
<SeriesNav post={post} postSeries={seriesPosts} />
) : null
}
</main> </main>
<footer role="contentinfo" class="post-lower-area"> <footer role="contentinfo" class="post-lower-area">
{ {

View File

@@ -1,7 +1,12 @@
import { ExtendedPostInfo } from "types/index"; import { ExtendedPostInfo } from "types/index";
export function getShortTitle(post: ExtendedPostInfo): string { export function getShortTitle(post: ExtendedPostInfo): string {
return post.title.replace(new RegExp(`^${post.series}: `), ""); const collectionTitle = post.collectionMeta?.title || post.collection;
// if the post title starts with its collection title, remove it
if (post.title.startsWith(`${collectionTitle}: `))
return post.title.substring(collectionTitle.length + 2);
return post.title;
} }
export function seperatePostsIntoThirds(seriesPosts: ExtendedPostInfo[]) { export function seperatePostsIntoThirds(seriesPosts: ExtendedPostInfo[]) {

View File

@@ -30,7 +30,7 @@ const isActiveInMiddle = middlePosts.some(
Part of our series: {collection.title} Part of our series: {collection.title}
</a> </a>
) : ( ) : (
`Part of our series: ${post.series}` `Part of our series: ${post.collection}`
) )
} }
</div> </div>