mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-07 21:07:47 +00:00
remove obsolete translations prop, rename series->collection for clarity
This commit is contained in:
@@ -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: [],
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
tags: ['networking'],
|
||||
attached: [],
|
||||
license: 'cc-by-nc-sa-4',
|
||||
series: "Networking 101",
|
||||
collection: "Networking 101",
|
||||
order: 1
|
||||
}
|
||||
---
|
||||
|
||||
@@ -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
|
||||
}
|
||||
---
|
||||
|
||||
@@ -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
|
||||
}
|
||||
---
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
tags: [],
|
||||
attached: [],
|
||||
license: 'cc-by-nc-sa-4',
|
||||
series: "minecraft-data-packs",
|
||||
collection: "minecraft-data-packs",
|
||||
order: 2
|
||||
}
|
||||
---
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
tags: [],
|
||||
attached: [],
|
||||
license: 'cc-by-nc-sa-4',
|
||||
series: "minecraft-data-packs",
|
||||
collection: "minecraft-data-packs",
|
||||
order: 1
|
||||
}
|
||||
---
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
tags: [],
|
||||
attached: [],
|
||||
license: 'cc-by-nc-sa-4',
|
||||
series: "minecraft-data-packs",
|
||||
collection: "minecraft-data-packs",
|
||||
order: 3
|
||||
}
|
||||
---
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
tags: ['networking'],
|
||||
attached: [],
|
||||
license: 'cc-by-nc-sa-4',
|
||||
series: "Networking 101",
|
||||
collection: "Networking 101",
|
||||
order: 2
|
||||
}
|
||||
---
|
||||
|
||||
@@ -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
|
||||
}
|
||||
---
|
||||
|
||||
@@ -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
|
||||
}
|
||||
---
|
||||
|
||||
@@ -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
|
||||
}
|
||||
---
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
tags: ['computer science'],
|
||||
attached: [],
|
||||
license: 'cc-by-4',
|
||||
series: "Explaining UUIDs",
|
||||
collection: "Explaining UUIDs",
|
||||
order: 1
|
||||
}
|
||||
---
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
tags: ['computer science'],
|
||||
attached: [],
|
||||
license: 'cc-by-4',
|
||||
series: "Explaining UUIDs",
|
||||
collection: "Explaining UUIDs",
|
||||
order: 2
|
||||
}
|
||||
---
|
||||
|
||||
@@ -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");
|
||||
---
|
||||
|
||||
<CardSolid class={style.container}>
|
||||
|
||||
@@ -39,11 +39,9 @@ const { Content, post, posts, locale } = Astro.props as {
|
||||
Content: MarkdownInstance<any>["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) : [];
|
||||
---
|
||||
|
||||
<Document lang={locale}>
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -35,11 +35,9 @@ const { Content, post, posts } = Astro.props as {
|
||||
Content: MarkdownInstance<any>["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) : [];
|
||||
---
|
||||
|
||||
<Document>
|
||||
|
||||
@@ -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<never>["Content"];
|
||||
excerpt: string;
|
||||
wordCount: number;
|
||||
translations: Partial<Record<Languages, string>>;
|
||||
suggestedArticles: [PostInfo, PostInfo, PostInfo];
|
||||
headingsWithId?: Array<{
|
||||
// Title value
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -150,8 +150,8 @@ function getPosts(): Array<PostInfo> {
|
||||
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`,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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]) || {};
|
||||
|
||||
|
||||
@@ -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);
|
||||
---
|
||||
|
||||
<CardInline class="d-flex" size="m">
|
||||
@@ -19,10 +26,10 @@ const path = removePrefixLanguageFromPath(Astro.url.pathname);
|
||||
<p class={style.text}>
|
||||
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 [
|
||||
<a href={href}>{languages[currLang]}</a>,
|
||||
<a href={href}>{languages[locale]}</a>,
|
||||
i !== arr.length - 1 ? ", " : null,
|
||||
];
|
||||
})
|
||||
|
||||
@@ -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) {
|
||||
</header>
|
||||
<main class="post-body" data-testid={"post-body-div"}>
|
||||
{
|
||||
post.series ? (
|
||||
post.collection ? (
|
||||
<SeriesToC
|
||||
post={post}
|
||||
postSeries={seriesPosts}
|
||||
@@ -88,12 +88,16 @@ if (post.series && post.order) {
|
||||
) : null
|
||||
}
|
||||
{
|
||||
post.translations && Object.keys(post.translations).length ? (
|
||||
<TranslationsHeader locales={Object.keys(post.translations)} />
|
||||
post.locales && post.locales.length > 1 ? (
|
||||
<TranslationsHeader locales={post.locales} />
|
||||
) : null
|
||||
}
|
||||
<Content />
|
||||
{post.series ? <SeriesNav post={post} postSeries={seriesPosts} /> : null}
|
||||
{
|
||||
post.collection ? (
|
||||
<SeriesNav post={post} postSeries={seriesPosts} />
|
||||
) : null
|
||||
}
|
||||
</main>
|
||||
<footer role="contentinfo" class="post-lower-area">
|
||||
{
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { ExtendedPostInfo } from "types/index";
|
||||
|
||||
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[]) {
|
||||
|
||||
@@ -30,7 +30,7 @@ const isActiveInMiddle = middlePosts.some(
|
||||
Part of our series: {collection.title}
|
||||
</a>
|
||||
) : (
|
||||
`Part of our series: ${post.series}`
|
||||
`Part of our series: ${post.collection}`
|
||||
)
|
||||
}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user