Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gets Astro.fetchContent compilation to work #1596

Merged
merged 4 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/portfolio/src/components/MainHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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">
2 changes: 1 addition & 1 deletion examples/portfolio/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/components/index.js
Original file line number Diff line number Diff line change
@@ -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';
4 changes: 2 additions & 2 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion packages/astro/src/vite-plugin-astro-postprocess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 };
},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/astro-sitemap-rss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this meant to change? just double checking that this is intentional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they were not sorted before, due to the component expected the frontmatter to be on the top-level object. When fixing that it caused the sorting to work again, and so this had to update.

]]></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>`
);
});
Expand All @@ -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`
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
Expand Down