Gets Astro.fetchContent compilation to work (#1596)
* Gets Astro.fetchContent compilation to work This fixes Astro.fetchContent so that we handle esbuild transforming the name of the nested Astro call. * Remove debugging * Update the tests * Remove another debugger
This commit is contained in:
parent
2ac2559b5d
commit
94a513adc6
7 changed files with 22 additions and 18 deletions
|
@ -7,6 +7,6 @@ const { title = 'Jeanine White: Personal Site' } = Astro.props;
|
|||
<title>{title}</title>
|
||||
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="/_astro/src/scss/global.css">
|
||||
<link rel="stylesheet" type="text/css" href="/src/scss/global.scss">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@200;400;700;900&display=swap" rel="stylesheet">
|
||||
|
|
|
@ -7,7 +7,7 @@ import Footer from '../components/Footer/index.jsx';
|
|||
import PortfolioPreview from '../components/PortfolioPreview/index.jsx';
|
||||
|
||||
// Data Fetching: List all Markdown posts in the repo.
|
||||
const projects = Astro.fetchContent('./project/**/*.md');
|
||||
const projects = Astro.fetchContent("./project/**/*.md");
|
||||
const featuredProject = projects[0];
|
||||
|
||||
// Full Astro Component Syntax:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// export { default as Code } from './Code.astro';
|
||||
// export { default as Debug } from './Debug.astro';
|
||||
//export { default as Code } from './Code.astro';
|
||||
//export { default as Debug } from './Debug.astro';
|
||||
export { default as Markdown } from './Markdown.astro';
|
||||
// export { default as Prism } from './Prism.astro';
|
||||
export { default as Prism } from './Prism.astro';
|
|
@ -258,10 +258,10 @@ function createFetchContentFn(url: URL) {
|
|||
}
|
||||
const urlSpec = new URL(spec, url).pathname.replace(/[\\/\\\\]/, '/');
|
||||
return {
|
||||
...mod.frontmatter,
|
||||
content: mod.metadata,
|
||||
metadata: mod.frontmatter,
|
||||
file: new URL(spec, url),
|
||||
url: urlSpec.includes('/pages/') && urlSpec.replace(/^.*\/pages\//, '/').replace(/\.md$/, ''),
|
||||
url: urlSpec.includes('/pages/') && urlSpec.replace(/^.*\/pages\//, '/').replace(/\.md$/, '')
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
|
|
@ -11,6 +11,9 @@ interface AstroPluginOptions {
|
|||
devServer?: AstroDevServer;
|
||||
}
|
||||
|
||||
// esbuild transforms the component-scoped Astro into Astro2, so need to check both.
|
||||
const validAstroGlobalNames = new Set(['Astro', 'Astro2']);
|
||||
|
||||
export default function astro({ config, devServer }: AstroPluginOptions): Plugin {
|
||||
return {
|
||||
name: '@astrojs/vite-plugin-astro-postprocess',
|
||||
|
@ -38,7 +41,7 @@ export default function astro({ config, devServer }: AstroPluginOptions): Plugin
|
|||
if (
|
||||
path.parent.type !== 'CallExpression' ||
|
||||
path.parent.callee.type !== 'MemberExpression' ||
|
||||
(path.parent.callee.object as any).name !== 'Astro' ||
|
||||
!validAstroGlobalNames.has((path.parent.callee.object as any).name) ||
|
||||
(path.parent.callee.property as any).name !== 'fetchContent'
|
||||
) {
|
||||
return;
|
||||
|
@ -68,6 +71,7 @@ export default function astro({ config, devServer }: AstroPluginOptions): Plugin
|
|||
if (!result || !result.code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return { code: result.code, map: result.map };
|
||||
},
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ describe('RSS Generation', () => {
|
|||
it('generates RSS correctly', async () => {
|
||||
const rss = await fixture.readFile('/custom/feed.xml');
|
||||
expect(rss).to.equal(
|
||||
`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title><![CDATA[MF Doomcast]]></title><description><![CDATA[The podcast about the things you find on a picnic, or at a picnic table]]></description><link>https://astro.build/custom/feed.xml</link><language>en-us</language><itunes:author>MF Doom</itunes:author><item><title><![CDATA[Fazers]]></title><link>https://astro.build/episode/fazers/</link><description><![CDATA[Rhapsody ranked Take Me to Your Leader 17th on its list “Hip-Hop’s Best Albums of the Decade”]]></description><pubDate>Thu, 03 Jul 2003 00:00:00 GMT</pubDate><itunes:episodeType>music</itunes:episodeType><itunes:duration>197</itunes:duration><itunes:explicit>true</itunes:explicit></item><item><title><![CDATA[Rap Snitch Knishes (feat. Mr. Fantastik)]]></title><link>https://astro.build/episode/rap-snitch-knishes/</link><description><![CDATA[Complex named this song the “22nd funniest rap song of all time.”]]></description><pubDate>Tue, 16 Nov 2004 00:00:00 GMT</pubDate><itunes:episodeType>music</itunes:episodeType><itunes:duration>172</itunes:duration><itunes:explicit>true</itunes:explicit></item><item><title><![CDATA[Rhymes Like Dimes (feat. Cucumber Slice)]]></title><link>https://astro.build/episode/rhymes-like-dimes/</link><description><![CDATA[Operation: Doomsday has been heralded as an underground classic that established MF Doom's rank within the underground hip-hop scene during the early to mid-2000s.
|
||||
`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title><![CDATA[MF Doomcast]]></title><description><![CDATA[The podcast about the things you find on a picnic, or at a picnic table]]></description><link>https://astro.build/custom/feed.xml</link><language>en-us</language><itunes:author>MF Doom</itunes:author><item><title><![CDATA[Rap Snitch Knishes (feat. Mr. Fantastik)]]></title><link>https://astro.build/episode/rap-snitch-knishes/</link><description><![CDATA[Complex named this song the “22nd funniest rap song of all time.”]]></description><pubDate>Tue, 16 Nov 2004 00:00:00 GMT</pubDate><itunes:episodeType>music</itunes:episodeType><itunes:duration>172</itunes:duration><itunes:explicit>true</itunes:explicit></item><item><title><![CDATA[Fazers]]></title><link>https://astro.build/episode/fazers/</link><description><![CDATA[Rhapsody ranked Take Me to Your Leader 17th on its list “Hip-Hop’s Best Albums of the Decade”]]></description><pubDate>Thu, 03 Jul 2003 00:00:00 GMT</pubDate><itunes:episodeType>music</itunes:episodeType><itunes:duration>197</itunes:duration><itunes:explicit>true</itunes:explicit></item><item><title><![CDATA[Rhymes Like Dimes (feat. Cucumber Slice)]]></title><link>https://astro.build/episode/rhymes-like-dimes/</link><description><![CDATA[Operation: Doomsday has been heralded as an underground classic that established MF Doom's rank within the underground hip-hop scene during the early to mid-2000s.
|
||||
]]></description><pubDate>Tue, 19 Oct 1999 00:00:00 GMT</pubDate><itunes:episodeType>music</itunes:episodeType><itunes:duration>259</itunes:duration><itunes:explicit>true</itunes:explicit></item></channel></rss>`
|
||||
);
|
||||
});
|
||||
|
@ -31,4 +31,4 @@ describe('Sitemap Generation', () => {
|
|||
`<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://astro.build/404/index.html</loc></url><url><loc>https://astro.build/episode/fazers/index.html</loc></url><url><loc>https://astro.build/episode/rap-snitch-knishes/index.html</loc></url><url><loc>https://astro.build/episode/rhymes-like-dimes/index.html</loc></url><url><loc>https://astro.build/episodes/index.html</loc></url></urlset>\n`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -10,14 +10,14 @@ export function getStaticPaths({paginate, rss}) {
|
|||
},
|
||||
customData: `<language>en-us</language>` +
|
||||
`<itunes:author>MF Doom</itunes:author>`,
|
||||
items: episodes.map(({ metadata, url }) => ({
|
||||
title: metadata.title,
|
||||
link: url,
|
||||
description: metadata.description,
|
||||
pubDate: metadata.pubDate + 'Z',
|
||||
customData: `<itunes:episodeType>${metadata.type}</itunes:episodeType>` +
|
||||
`<itunes:duration>${metadata.duration}</itunes:duration>` +
|
||||
`<itunes:explicit>${metadata.explicit || false}</itunes:explicit>`,
|
||||
items: episodes.map((episode) => ({
|
||||
title: episode.title,
|
||||
link: episode.url,
|
||||
description: episode.description,
|
||||
pubDate: episode.pubDate + 'Z',
|
||||
customData: `<itunes:episodeType>${episode.type}</itunes:episodeType>` +
|
||||
`<itunes:duration>${episode.duration}</itunes:duration>` +
|
||||
`<itunes:explicit>${episode.explicit || false}</itunes:explicit>`,
|
||||
})),
|
||||
dest: '/custom/feed.xml',
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue