Skip to content

Commit 84c6eca

Browse files
committed
important commit: restructure content folders with generateId() for slug formatting, works
1 parent a993ede commit 84c6eca

File tree

22 files changed

+93
-49
lines changed

22 files changed

+93
-49
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const args = {args: {
2+
entry: '2024/example-article-4/index.mdx',
3+
base: {
4+
href: 'file:///home/username/Desktop/nemanjam.github.io/src/content/post/',
5+
origin: 'null',
6+
protocol: 'file:',
7+
username: '',
8+
password: '',
9+
host: '',
10+
hostname: '',
11+
port: '',
12+
pathname: '/home/username/Desktop/nemanjam.github.io/src/content/post/',
13+
search: '',
14+
// searchParams: URLSearchParams {},
15+
hash: ''
16+
},
17+
data: {
18+
title: 'Example article 4 commodo ea ipsum tempor nisi aliqua',
19+
description: 'Dolor velit excepteur cupidatat: Aute in fugiat id reprehenderit ipsum qui tempor fugiat. Excepteur tempor culpa velit duis quis enim aliquip.\n',
20+
publishDate: 2024-01-20T00:00:00.000Z,
21+
updatedDate: 2024-05-23T00:00:00.000Z,
22+
heroImage: '../../../../content/post/2024/example-article-4/_images/river1.jpg',
23+
heroAlt: 'sunt aute reprehenderit exercitation cillum culpa dolor dolor commodo ea ipsum tempor nisi aliqua.',
24+
noHero: false,
25+
tags: [ 'devops', 'css', 'react', 'astro' ],
26+
category: 'tools',
27+
toc: true
28+
}
29+
}

docs/working-notes/todo4.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,11 @@ git checkout -b feature/content-layer
3535
id, slug, decoupled with my custom type Post[], Project[], from CollectionEntry<T>
3636
folder name with slug and colocated images
3737
remote collection for links page?
38+
-----------
39+
folders with index
40+
https://github.dev/LeaVerou/lea.verou.me
41+
42+
git checkout -b refactor/folder-slug
43+
44+
3845
```

src/content/config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ import { BASE_FOLDERS } from '@/constants/collections';
77

88
const { POST, PROJECT } = BASE_FOLDERS;
99

10+
/**
11+
* Format id slug. Remove '/' to avoid catch all [...page].astro route.
12+
*
13+
* @example filepath: 2024/03-15-example-project-2/index.mdx -> slug: 2024-03-15-example-project-2
14+
*/
15+
const generateId = ({ entry }: { entry: string }) => entry.split('/').slice(0, 2).join('-');
16+
1017
export const postCollection = defineCollection({
11-
loader: glob({ pattern: '**/*.mdx', base: POST }),
18+
loader: glob({ pattern: '**/*.mdx', base: POST, generateId }),
1219
schema: postSchema,
1320
});
1421

1522
export const projectCollection = defineCollection({
16-
loader: glob({ pattern: '**/*.mdx', base: PROJECT }),
23+
loader: glob({ pattern: '**/*.mdx', base: PROJECT, generateId }),
1724
schema: projectSchema,
1825
});
1926

src/content/post/2022-02-16-example-article-1.mdx renamed to src/content/post/2022/02-16-example-article-1/index.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Example article 1
33
description: |
44
Et dolor tempor velit: Aute ad tempor incididunt labore dolore incididunt in quis officia quis est. Ullamco aute et ex velit proident non.
55
publishDate: 2022-02-16
6-
heroImage: '../../content/post/_images/2022-02-16-example-article-1/focus1.jpg'
6+
heroImage: '../../../../content/post/2022/02-16-example-article-1/_images/focus1.jpg'
77
heroAlt: sunt aute reprehenderit exercitation cillum culpa dolor dolor commodo ea ipsum tempor nisi aliqua.
88
tags:
99
- astro
@@ -17,11 +17,11 @@ toc: true
1717
import { Icon } from 'astro-icon/components';
1818
import { Image } from 'astro:assets';
1919

20-
import Alert from '../../components/Alert.astro';
21-
import Button from '../../components/Button.astro';
22-
import { IMAGE_SIZES } from '../../constants/image';
20+
import Alert from '../../../../components/Alert.astro';
21+
import Button from '../../../../components/Button.astro';
22+
import { IMAGE_SIZES } from '../../../../constants/image';
2323

24-
import BicycleImage from '../../content/post/_images/2022-02-16-example-article-1/focus1.jpg';
24+
import BicycleImage from '../../../../content/post/2022/02-16-example-article-1/_images/focus1.jpg';
2525

2626

2727
Ut exercitation occaecat in velit [nulla aliqua](#) eiusmod laboris ex. Officia dolore ipsum aliqua irure qui non ea elit veniam aute ex incididunt. Elit incididunt dolor velit velit magna. Nulla occaecat ut dolore ullamco amet aliqua laborum velit cillum.

src/content/post/2022-03-17-example-article-2.mdx renamed to src/content/post/2022/03-17-example-article-2/index.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Example article 2 dolor commodo ea ipsum tempor nisi aliqua
33
description: |
44
Dolor velit excepteur cupidatat: Aute in fugiat id reprehenderit ipsum qui tempor fugiat. Excepteur tempor culpa velit duis quis enim aliquip.
55
publishDate: 2022-03-17
6-
heroImage: '../../content/post/_images/2022-03-17-example-article-2/riverside1.jpg'
6+
heroImage: '../../../../content/post/2022/03-17-example-article-2/_images/riverside1.jpg'
77
heroAlt: sunt aute reprehenderit exercitation cillum culpa dolor dolor commodo ea ipsum tempor nisi aliqua.
88
tags:
99
- css
@@ -17,11 +17,11 @@ toc: true
1717
import { Icon } from 'astro-icon/components';
1818
import { Image } from 'astro:assets';
1919

20-
import Alert from '../../components/Alert.astro';
21-
import Button from '../../components/Button.astro';
22-
import { IMAGE_SIZES } from '../../constants/image';
20+
import Alert from '../../../../components/Alert.astro';
21+
import Button from '../../../../components/Button.astro';
22+
import { IMAGE_SIZES } from '../../../../constants/image';
2323

24-
import BicycleImage from '../../content/post/_images/2022-03-17-example-article-2/riverside1.jpg';
24+
import BicycleImage from '../../../../content/post/2022/03-17-example-article-2/_images/riverside1.jpg';
2525

2626

2727
Ut exercitation occaecat in velit [nulla aliqua](#) eiusmod laboris ex. Officia dolore ipsum aliqua irure qui non ea elit veniam aute ex incididunt. Elit incididunt dolor velit velit magna. Nulla occaecat ut dolore ullamco amet aliqua laborum velit cillum.
File renamed without changes.

src/content/post/2023-01-19-example-article-3.mdx renamed to src/content/post/2023/01-19-example-article-3/index.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Example article 3 reprehenderit ipsum qui tempor
33
description: |
44
Dolor velit excepteur cupidatat: Aute in fugiat id reprehenderit ipsum qui tempor fugiat. Excepteur tempor culpa velit duis quis enim aliquip.
55
publishDate: 2023-01-19
6-
heroImage: '../../content/post/_images/2023-01-19-example-article-3/lure1.jpg'
6+
heroImage: '../../../../content/post/2023/01-19-example-article-3/_images/lure1.jpg'
77
heroAlt: sunt aute reprehenderit exercitation cillum culpa dolor dolor commodo ea ipsum tempor nisi aliqua.
88
tags:
99
- devops
@@ -18,11 +18,11 @@ toc: true
1818
import { Icon } from 'astro-icon/components';
1919
import { Image } from 'astro:assets';
2020

21-
import Alert from '../../components/Alert.astro';
22-
import Button from '../../components/Button.astro';
23-
import { IMAGE_SIZES } from '../../constants/image';
21+
import Alert from '../../../../components/Alert.astro';
22+
import Button from '../../../../components/Button.astro';
23+
import { IMAGE_SIZES } from '../../../../constants/image';
2424

25-
import LureImage from '../../content/post/_images/2023-01-19-example-article-3/lure1.jpg';
25+
import LureImage from '../../../../content/post/2023/01-19-example-article-3/_images/lure1.jpg';
2626

2727

2828
Ut exercitation occaecat in velit [nulla aliqua](#) eiusmod laboris ex. Officia dolore ipsum aliqua irure qui non ea elit veniam aute ex incididunt. Elit incididunt dolor velit velit magna. Nulla occaecat ut dolore ullamco amet aliqua laborum velit cillum.

0 commit comments

Comments
 (0)