From 86c2fbe2dee89b2f5366c97079d51024f70e0d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20UB?= <22903142+adrian-ub@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:08:27 -0500 Subject: [PATCH] feat: add fallback lang --- .../pages/es/posts/markdown-style-guide.md | 215 ++++++++++++++++++ playground/src/content/pages/podcasts.mdx | 2 +- .../src/content/pages/posts/redirect.mdx | 6 + src/components/ListPosts.astro | 131 +++++++---- 4 files changed, 315 insertions(+), 39 deletions(-) create mode 100644 playground/src/content/pages/es/posts/markdown-style-guide.md create mode 100644 playground/src/content/pages/posts/redirect.mdx diff --git a/playground/src/content/pages/es/posts/markdown-style-guide.md b/playground/src/content/pages/es/posts/markdown-style-guide.md new file mode 100644 index 0000000..dccee2b --- /dev/null +++ b/playground/src/content/pages/es/posts/markdown-style-guide.md @@ -0,0 +1,215 @@ +--- +title: 'Guía de estilo de Markdown' +date: '2024-10-04' +duration: 5min +--- + +[[toc]] + +Here is a sample of some basic Markdown syntax that can be used when writing Markdown content in Astro. + +## Headings + +The following HTML `

`—`

` elements represent six levels of section headings. `

` is the highest section level while `

` is the lowest. + +# H1 + +## H2 + +### H3 + +#### H4 + +##### H5 + +###### H6 + +## Paragraph + +Xerum, quo qui aut unt expliquam qui dolut labo. Aque venitatiusda cum, voluptionse latur sitiae dolessi aut parist aut dollo enim qui voluptate ma dolestendit peritin re plis aut quas inctum laceat est volestemque commosa as cus endigna tectur, offic to cor sequas etum rerum idem sintibus eiur? Quianimin porecus evelectur, cum que nis nust voloribus ratem aut omnimi, sitatur? Quiatem. Nam, omnis sum am facea corem alique molestrunt et eos evelece arcillit ut aut eos eos nus, sin conecerem erum fuga. Ri oditatquam, ad quibus unda veliamenimin cusam et facea ipsamus es exerum sitate dolores editium rerore eost, temped molorro ratiae volorro te reribus dolorer sperchicium faceata tiustia prat. + +Itatur? Quiatae cullecum rem ent aut odis in re eossequodi nonsequ idebis ne sapicia is sinveli squiatum, core et que aut hariosam ex eat. + +## Images + +### Syntax + +```markdown +![Alt text](./full/or/relative/path/of/image) +``` + +### Output + +![blog placeholder](/blog-placeholder-about.jpg) + +## Blockquotes + +The blockquote element represents content that is quoted from another source, optionally with a citation which must be within a `footer` or `cite` element, and optionally with in-line changes such as annotations and abbreviations. + +### Blockquote without attribution + +#### Syntax + +```markdown +> Tiam, ad mint andaepu dandae nostion secatur sequo quae. +> **Note** that you can use _Markdown syntax_ within a blockquote. +``` + +#### Output + +> Tiam, ad mint andaepu dandae nostion secatur sequo quae. +> **Note** that you can use _Markdown syntax_ within a blockquote. + +### Blockquote with attribution + +#### Syntax + +```markdown +> Don't communicate by sharing memory, share memory by communicating.
+> — Rob Pike[^1] +``` + +#### Output + +> Don't communicate by sharing memory, share memory by communicating.
+> — Rob Pike[^1] + +[^1]: The above quote is excerpted from Rob Pike's [talk](https://www.youtube.com/watch?v=PAAkCSZUG1c) during Gopherfest, November 18, 2015. + +## Tables + +### Syntax + +```markdown +| Italics | Bold | Code | +| --------- | -------- | ------ | +| _italics_ | **bold** | `code` | +``` + +### Output + +| Italics | Bold | Code | +| --------- | -------- | ------ | +| _italics_ | **bold** | `code` | + +## Code Blocks + +### Syntax + +we can use 3 backticks ``` in new line and write snippet and close with 3 backticks on new line and to highlight language specific syntax, write one word of language name after first 3 backticks, for eg. html, javascript, css, markdown, typescript, txt, bash + +````markdown +```html + + + + + Example HTML5 Document + + +

Test

+ + +``` +```` + +### Output + +```html + + + + + Example HTML5 Document + + +

Test

+ + +``` + +## List Types + +### Ordered List + +#### Syntax + +```markdown +1. First item +2. Second item +3. Third item +``` + +#### Output + +1. First item +2. Second item +3. Third item + +### Unordered List + +#### Syntax + +```markdown +- List item +- Another item +- And another item +``` + +#### Output + +- List item +- Another item +- And another item + +### Nested list + +#### Syntax + +```markdown +- Fruit + - Apple + - Orange + - Banana +- Dairy + - Milk + - Cheese +``` + +#### Output + +- Fruit + - Apple + - Orange + - Banana +- Dairy + - Milk + - Cheese + +## Other Elements — abbr, sub, sup, kbd, mark + +### Syntax + +```markdown +GIF is a bitmap image format. + +H2O + +Xn + Yn = Zn + +Press CTRL + ALT + Delete to end the session. + +Most salamanders are nocturnal, and hunt for insects, worms, and other small creatures. +``` + +### Output + +GIF is a bitmap image format. + +H2O + +Xn + Yn = Zn + +Press CTRL + ALT + Delete to end the session. + +Most salamanders are nocturnal, and hunt for insects, worms, and other small creatures. diff --git a/playground/src/content/pages/podcasts.mdx b/playground/src/content/pages/podcasts.mdx index aa11e4b..3362d0f 100644 --- a/playground/src/content/pages/podcasts.mdx +++ b/playground/src/content/pages/podcasts.mdx @@ -13,4 +13,4 @@ import ListPosts from 'astro-vitesse/components/ListPosts.astro' - + diff --git a/playground/src/content/pages/posts/redirect.mdx b/playground/src/content/pages/posts/redirect.mdx new file mode 100644 index 0000000..746eb11 --- /dev/null +++ b/playground/src/content/pages/posts/redirect.mdx @@ -0,0 +1,6 @@ +--- +title: 'Redirect' +redirect: https://github.com/adrian-ub/astro-vitesse +date: '2023-10-07' +duration: 5min +--- diff --git a/src/components/ListPosts.astro b/src/components/ListPosts.astro index 9cc6fa6..5984823 100644 --- a/src/components/ListPosts.astro +++ b/src/components/ListPosts.astro @@ -1,36 +1,71 @@ --- -import { CollectionEntry, getCollection } from 'astro:content' +import { CollectionEntry } from 'astro:content' import { formatDate } from '../logics' +import { slugToLocaleData } from '../utils/slugs' +import { ensureLeadingSlash, stripLeadingSlash } from '../utils/path' +import { getLocaleRoutes, Route, VitessePagesEntry } from '../utils/routing' +import { generateVitessePageRouteData } from '../utils/vitesse-page' export interface Props { startsWith?: string - posts?: CollectionEntry<'pages'>['data'][] + items?: CollectionEntry<'pages'>['data'][] } -const { startsWith = 'posts/', posts: postsProps } = Astro.props +let { startsWith = 'posts/', items: pagesProps } = Astro.props -let pages: CollectionEntry<'pages'>['data'][] = [] +let pagesCollection: Route[] = [] -if (!postsProps?.length) { - pages = ( - await getCollection('pages', (page) => { - return page.slug.startsWith(startsWith) - }) - ).map((page) => ({ ...page.data, path: page.data.path ?? page.data.redirect ?? page.slug })) +const localeData = slugToLocaleData(stripLeadingSlash(Astro.url.pathname)) +if (!pagesProps?.length) { + const routes = getLocaleRoutes(localeData.locale).filter((route) => + route.slug.startsWith((localeData.locale ? localeData.locale + '/' : '') + startsWith), + ) + pagesCollection = routes } -const posts: CollectionEntry<'pages'>['data'] = [...(postsProps || pages)].sort( - (a, b) => +new Date(b.date!) - +new Date(a.date!), -) +const newPagePros = [...(pagesProps || [])].map(async (page) => { + const { entry, slug, id, entryMeta, dir, lang, locale } = await generateVitessePageRouteData({ + url: Astro.url, + props: { + frontmatter: page, + lang: localeData.locale, + }, + }) + + return { + entry, + slug, + id, + entryMeta, + dir, + lang, + locale, + } +}) + +pagesProps = await Promise.all(newPagePros) + +const pages: Route[] = [...((pagesProps.length ? pagesProps : null) || pagesCollection)] + .sort((a, b) => +new Date(b.entry.data.date!) - +new Date(a.entry.data.date!)) + .map((page) => ({ + ...page, + entry: { + ...page.entry, + data: { + ...page.entry.data, + path: page.entry.data.path ?? page.entry.data.redirect ?? ensureLeadingSlash(page.slug), + }, + }, + })) const getYear = (a: Date | string | number) => new Date(a).getFullYear() const isFuture = (a?: Date | string | number) => a && new Date(a) > new Date() const isSameYear = (a?: Date | string | number, b?: Date | string | number) => a && b && getYear(a) === getYear(b) -function isSameGroup(a: CollectionEntry<'pages'>['data'], b?: CollectionEntry<'pages'>['data']) { +function isSameGroup(a: VitessePagesEntry, b?: VitessePagesEntry) { return isFuture(a.date) === isFuture(b?.date) && isSameYear(a.date, b?.date) } -function getGroupName(p: CollectionEntry<'pages'>['data']) { +function getGroupName(p: VitessePagesEntry) { if (isFuture(p.date)) return 'Upcoming' return getYear(p.date!) } @@ -38,7 +73,7 @@ function getGroupName(p: CollectionEntry<'pages'>['data']) {