diff --git a/src/components/PredictorDemo.vue b/src/components/PredictorDemo.vue index 87d6d9d..8349ea7 100644 --- a/src/components/PredictorDemo.vue +++ b/src/components/PredictorDemo.vue @@ -1,6 +1,9 @@ diff --git a/src/content/articles/2019-05-01-predictor.mdx b/src/content/articles/2019-05-01-predictor.mdx index eba9697..f6d46eb 100644 --- a/src/content/articles/2019-05-01-predictor.mdx +++ b/src/content/articles/2019-05-01-predictor.mdx @@ -30,7 +30,7 @@ import PredictorDemo from '../../components/PredictorDemo.vue'; --- - + --- diff --git a/src/pages/404.astro b/src/pages/404.astro new file mode 100644 index 0000000..0c666a1 --- /dev/null +++ b/src/pages/404.astro @@ -0,0 +1,8 @@ +--- +import InternalLayout from '../layouts/InternalLayout.astro'; +--- + +

404

+

Ой, страница не найдена.

+

Давайте посмотрим, что интересное есть на главной.

+
diff --git a/src/pages/articles/[slug].astro b/src/pages/articles/[slug].astro new file mode 100644 index 0000000..7ae93be --- /dev/null +++ b/src/pages/articles/[slug].astro @@ -0,0 +1,25 @@ +--- +import { getCollection, render } from 'astro:content'; +import ArticleLayout from '../../layouts/ArticleLayout.astro'; +import { parseDateFromId } from '../../utils/articles'; + +export async function getStaticPaths() { + const articles = await getCollection('articles'); + return articles.map((article) => ({ + params: { slug: article.id }, + props: { article }, + })); +} + +const { article } = Astro.props; +const { Content } = await render(article); +const date = parseDateFromId(article.id); +--- + + + diff --git a/src/pages/articles/index.astro b/src/pages/articles/index.astro new file mode 100644 index 0000000..16ae2e1 --- /dev/null +++ b/src/pages/articles/index.astro @@ -0,0 +1,16 @@ +--- +import { getCollection } from 'astro:content'; +import InternalLayout from '../../layouts/InternalLayout.astro'; +import ArticleList from '../../components/ArticleList.astro'; +import { parseDateFromId } from '../../utils/articles'; + +const allArticles = await getCollection('articles', ({ data }) => !data.draft); +const articles = allArticles.map((a) => ({ + slug: a.id, + date: parseDateFromId(a.id), + title: a.data.title, +})); +--- + + + diff --git a/src/pages/gallery/index.astro b/src/pages/gallery/index.astro new file mode 100644 index 0000000..a8d8473 --- /dev/null +++ b/src/pages/gallery/index.astro @@ -0,0 +1,7 @@ +--- +import InternalLayout from '../../layouts/InternalLayout.astro'; +--- + +

Галерея

+

Скоро здесь будут фотографии.

+
diff --git a/src/pages/index.astro b/src/pages/index.astro index 7c5db96..3a48b8e 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,5 +1,15 @@ --- +import { getCollection } from 'astro:content'; import BaseLayout from '../layouts/BaseLayout.astro'; +import ArticleList from '../components/ArticleList.astro'; +import { parseDateFromId } from '../utils/articles'; + +const allArticles = await getCollection('articles', ({ data }) => !data.draft); +const articles = allArticles.map((a) => ({ + slug: a.id, + date: parseDateFromId(a.id), + title: a.data.title, +})); ---
@@ -13,6 +23,10 @@ import BaseLayout from '../layouts/BaseLayout.astro';
+ + +
+
  • anton@vakhrushev.me diff --git a/src/utils/articles.ts b/src/utils/articles.ts new file mode 100644 index 0000000..8df6a61 --- /dev/null +++ b/src/utils/articles.ts @@ -0,0 +1,10 @@ +/** + * Парсит дату из ID статьи (формат: "2019-05-01-slug"). + */ +export function parseDateFromId(id: string): Date { + const match = id.match(/^(\d{4})-(\d{2})-(\d{2})-/); + if (!match) { + throw new Error(`Cannot parse date from article id: ${id}`); + } + return new Date(`${match[1]}-${match[2]}-${match[3]}`); +}