-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'content-layer' into feat/inject-types
- Loading branch information
Showing
99 changed files
with
4,458 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Implements Content Layer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import fs from 'node:fs/promises'; | ||
import { loremIpsumMd } from './_util.js'; | ||
|
||
/** | ||
* @param {URL} projectDir | ||
*/ | ||
export async function run(projectDir) { | ||
await fs.rm(projectDir, { recursive: true, force: true }); | ||
await fs.mkdir(new URL('./src/pages/blog', projectDir), { recursive: true }); | ||
await fs.mkdir(new URL('./src/content/blog', projectDir), { recursive: true }); | ||
await fs.copyFile(new URL('./image.jpg', import.meta.url), new URL('./src/image.jpg', projectDir)); | ||
|
||
const promises = []; | ||
|
||
|
||
for (let i = 0; i < 10000; i++) { | ||
const content = `\ | ||
# Article ${i} | ||
${loremIpsumMd} | ||
![image ${i}](../../image.jpg) | ||
`; | ||
promises.push( | ||
fs.writeFile(new URL(`./src/content/blog/article-${i}.md`, projectDir), content, 'utf-8') | ||
); | ||
} | ||
|
||
|
||
await fs.writeFile( | ||
new URL(`./src/pages/blog/[...slug].astro`, projectDir), | ||
`\ | ||
--- | ||
import { getCollection } from 'astro:content'; | ||
export async function getStaticPaths() { | ||
const blogEntries = await getCollection('blog'); | ||
return blogEntries.map(entry => ({ | ||
params: { slug: entry.slug }, props: { entry }, | ||
})); | ||
} | ||
const { entry } = Astro.props; | ||
const { Content } = await entry.render(); | ||
--- | ||
<h1>{entry.data.title}</h1> | ||
<Content /> | ||
`, | ||
'utf-8' | ||
); | ||
|
||
await Promise.all(promises); | ||
|
||
await fs.writeFile( | ||
new URL('./astro.config.js', projectDir), | ||
`\ | ||
import { defineConfig } from 'astro/config'; | ||
export default defineConfig({ | ||
});`, | ||
'utf-8' | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import fs from 'node:fs/promises'; | ||
import { loremIpsumMd } from './_util.js'; | ||
|
||
/** | ||
* @param {URL} projectDir | ||
*/ | ||
export async function run(projectDir) { | ||
await fs.rm(projectDir, { recursive: true, force: true }); | ||
await fs.mkdir(new URL('./src/pages/blog', projectDir), { recursive: true }); | ||
await fs.mkdir(new URL('./data/blog', projectDir), { recursive: true }); | ||
await fs.mkdir(new URL('./src/content', projectDir), { recursive: true }); | ||
await fs.copyFile(new URL('./image.jpg', import.meta.url), new URL('./image.jpg', projectDir)); | ||
|
||
const promises = []; | ||
|
||
for (let i = 0; i < 10000; i++) { | ||
const content = `\ | ||
# Article ${i} | ||
${loremIpsumMd} | ||
![image ${i}](../../image.jpg) | ||
`; | ||
promises.push( | ||
fs.writeFile(new URL(`./data/blog/article-${i}.md`, projectDir), content, 'utf-8') | ||
); | ||
} | ||
|
||
await fs.writeFile( | ||
new URL(`./src/content/config.ts`, projectDir), | ||
/*ts */ ` | ||
import { defineCollection, z } from 'astro:content'; | ||
import { glob } from 'astro/loaders'; | ||
const blog = defineCollection({ | ||
loader: glob({ pattern: '*', base: './data/blog' }), | ||
}); | ||
export const collections = { blog } | ||
` | ||
); | ||
|
||
await fs.writeFile( | ||
new URL(`./src/pages/blog/[...slug].astro`, projectDir), | ||
`\ | ||
--- | ||
import { getCollection, render } from 'astro:content'; | ||
export async function getStaticPaths() { | ||
const blogEntries = await getCollection('blog'); | ||
return blogEntries.map(entry => ({ | ||
params: { slug: entry.id }, props: { entry }, | ||
})); | ||
} | ||
const { entry } = Astro.props; | ||
const { Content } = await render(entry); | ||
--- | ||
<h1>{entry.data.title}</h1> | ||
<Content /> | ||
`, | ||
'utf-8' | ||
); | ||
|
||
await Promise.all(promises); | ||
|
||
await fs.writeFile( | ||
new URL('./astro.config.js', projectDir), | ||
`\ | ||
import { defineConfig } from 'astro/config'; | ||
export default defineConfig({ | ||
experimental: { | ||
contentLayer: true | ||
} | ||
});`, | ||
'utf-8' | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import fs from 'node:fs/promises'; | ||
import { loremIpsumMd } from './_util.js'; | ||
|
||
/** | ||
* @param {URL} projectDir | ||
*/ | ||
export async function run(projectDir) { | ||
await fs.rm(projectDir, { recursive: true, force: true }); | ||
await fs.mkdir(new URL('./src/pages/blog', projectDir), { recursive: true }); | ||
await fs.mkdir(new URL('./src/content/blog', projectDir), { recursive: true }); | ||
await fs.copyFile(new URL('./image.jpg', import.meta.url), new URL('./src/image.jpg', projectDir)); | ||
|
||
const promises = []; | ||
|
||
|
||
for (let i = 0; i < 10000; i++) { | ||
const content = `\ | ||
# Article ${i} | ||
${loremIpsumMd} | ||
![image ${i}](../../image.jpg) | ||
`; | ||
promises.push( | ||
fs.writeFile(new URL(`./src/content/blog/article-${i}.mdx`, projectDir), content, 'utf-8') | ||
); | ||
} | ||
|
||
|
||
await fs.writeFile( | ||
new URL(`./src/pages/blog/[...slug].astro`, projectDir), | ||
`\ | ||
--- | ||
import { getCollection } from 'astro:content'; | ||
export async function getStaticPaths() { | ||
const blogEntries = await getCollection('blog'); | ||
return blogEntries.map(entry => ({ | ||
params: { slug: entry.slug }, props: { entry }, | ||
})); | ||
} | ||
const { entry } = Astro.props; | ||
const { Content } = await entry.render(); | ||
--- | ||
<h1>{entry.data.title}</h1> | ||
<Content /> | ||
`, | ||
'utf-8' | ||
); | ||
|
||
await Promise.all(promises); | ||
|
||
await fs.writeFile( | ||
new URL('./astro.config.js', projectDir), | ||
`\ | ||
import { defineConfig } from 'astro/config'; | ||
import mdx from '@astrojs/mdx'; | ||
export default defineConfig({ | ||
integrations: [mdx()], | ||
});`, | ||
'utf-8' | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import fs from 'node:fs/promises'; | ||
import { loremIpsumMd } from './_util.js'; | ||
|
||
/** | ||
* @param {URL} projectDir | ||
*/ | ||
export async function run(projectDir) { | ||
await fs.rm(projectDir, { recursive: true, force: true }); | ||
await fs.mkdir(new URL('./src/pages/blog', projectDir), { recursive: true }); | ||
await fs.mkdir(new URL('./data/blog', projectDir), { recursive: true }); | ||
await fs.mkdir(new URL('./src/content', projectDir), { recursive: true }); | ||
await fs.copyFile(new URL('./image.jpg', import.meta.url), new URL('./image.jpg', projectDir)); | ||
|
||
const promises = []; | ||
|
||
for (let i = 0; i < 10000; i++) { | ||
const content = `\ | ||
# Article ${i} | ||
${loremIpsumMd} | ||
![image ${i}](../../image.jpg) | ||
`; | ||
promises.push( | ||
fs.writeFile(new URL(`./data/blog/article-${i}.mdx`, projectDir), content, 'utf-8') | ||
); | ||
} | ||
|
||
await fs.writeFile( | ||
new URL(`./src/content/config.ts`, projectDir), | ||
/*ts */ ` | ||
import { defineCollection, z } from 'astro:content'; | ||
import { glob } from 'astro/loaders'; | ||
const blog = defineCollection({ | ||
loader: glob({ pattern: '*', base: './data/blog' }), | ||
}); | ||
export const collections = { blog } | ||
` | ||
); | ||
|
||
await fs.writeFile( | ||
new URL(`./src/pages/blog/[...slug].astro`, projectDir), | ||
`\ | ||
--- | ||
import { getCollection, render } from 'astro:content'; | ||
export async function getStaticPaths() { | ||
const blogEntries = await getCollection('blog'); | ||
return blogEntries.map(entry => ({ | ||
params: { slug: entry.id }, props: { entry }, | ||
})); | ||
} | ||
const { entry } = Astro.props; | ||
const { Content } = await render(entry); | ||
--- | ||
<h1>{entry.data.title}</h1> | ||
<Content /> | ||
`, | ||
'utf-8' | ||
); | ||
|
||
await Promise.all(promises); | ||
|
||
await fs.writeFile( | ||
new URL('./astro.config.js', projectDir), | ||
`\ | ||
import { defineConfig } from 'astro/config'; | ||
import mdx from '@astrojs/mdx'; | ||
export default defineConfig({ | ||
integrations: [mdx()], | ||
experimental: { | ||
contentLayer: true | ||
} | ||
});`, | ||
'utf-8' | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.