|
|
|
@ -4,10 +4,15 @@ import path from 'node:path'
|
|
|
|
|
|
|
|
|
|
|
|
import { resolveConfig } from 'node/config'
|
|
|
|
import { resolveConfig } from 'node/config'
|
|
|
|
import { createContentLoader } from 'node/contentLoader'
|
|
|
|
import { createContentLoader } from 'node/contentLoader'
|
|
|
|
|
|
|
|
import { disposeMdItInstance } from 'node/markdown/markdown'
|
|
|
|
|
|
|
|
|
|
|
|
describe('node/contentLoader', () => {
|
|
|
|
describe('node/contentLoader', () => {
|
|
|
|
let root: string | undefined
|
|
|
|
let root: string | undefined
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
|
|
|
disposeMdItInstance()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
afterEach(async () => {
|
|
|
|
if (root) {
|
|
|
|
if (root) {
|
|
|
|
await rm(root, { recursive: true, force: true })
|
|
|
|
await rm(root, { recursive: true, force: true })
|
|
|
|
@ -76,4 +81,52 @@ describe('node/contentLoader', () => {
|
|
|
|
|
|
|
|
|
|
|
|
expect(data[0].excerpt).toContain('Intro says My Post.')
|
|
|
|
expect(data[0].excerpt).toContain('Intro says My Post.')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test.each([false, true])(
|
|
|
|
|
|
|
|
'uses the rewritten locale for rendered content and excerpts (render: %s)',
|
|
|
|
|
|
|
|
async (render) => {
|
|
|
|
|
|
|
|
await setup(false)
|
|
|
|
|
|
|
|
await mkdir(path.join(root!, '.vitepress'))
|
|
|
|
|
|
|
|
await writeFile(
|
|
|
|
|
|
|
|
path.join(root!, '.vitepress/config.mjs'),
|
|
|
|
|
|
|
|
`export default {
|
|
|
|
|
|
|
|
rewrites: { 'translated.md': 'fr/post.md' },
|
|
|
|
|
|
|
|
locales: {
|
|
|
|
|
|
|
|
root: { label: 'English', lang: 'en' },
|
|
|
|
|
|
|
|
fr: {
|
|
|
|
|
|
|
|
label: 'French', lang: 'fr',
|
|
|
|
|
|
|
|
markdown: { container: { tipLabel: 'Conseil' } }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}`
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
const content = '# Post\n\n::: tip\nSome advice.\n:::\n\n---\n\nBody.\n'
|
|
|
|
|
|
|
|
await writeFile(path.join(root!, 'translated.md'), content)
|
|
|
|
|
|
|
|
await writeFile(path.join(root!, 'original.md'), content)
|
|
|
|
|
|
|
|
await mkdir(path.join(root!, 'fr'))
|
|
|
|
|
|
|
|
await writeFile(path.join(root!, 'fr/native.md'), content)
|
|
|
|
|
|
|
|
;(global as any).VITEPRESS_CONFIG = await resolveConfig(
|
|
|
|
|
|
|
|
root!,
|
|
|
|
|
|
|
|
'build',
|
|
|
|
|
|
|
|
'production'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const data = await createContentLoader(
|
|
|
|
|
|
|
|
['translated.md', 'original.md', 'fr/native.md'],
|
|
|
|
|
|
|
|
{ render, excerpt: true }
|
|
|
|
|
|
|
|
).load()
|
|
|
|
|
|
|
|
const translated = data.find((page) => page.url === '/fr/post.html')!
|
|
|
|
|
|
|
|
const native = data.find((page) => page.url === '/fr/native.html')!
|
|
|
|
|
|
|
|
const original = data.find((page) => page.url === '/original.html')!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(translated.excerpt).toContain('Conseil')
|
|
|
|
|
|
|
|
expect(native.excerpt).toContain('Conseil')
|
|
|
|
|
|
|
|
expect(original.excerpt).toContain('TIP')
|
|
|
|
|
|
|
|
if (render) {
|
|
|
|
|
|
|
|
expect(translated.html).toContain('Conseil')
|
|
|
|
|
|
|
|
expect(native.html).toContain('Conseil')
|
|
|
|
|
|
|
|
expect(original.html).toContain('TIP')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|