diff --git a/.changeset/clever-cobras-notice.md b/.changeset/clever-cobras-notice.md new file mode 100644 index 000000000..79ddedc8c --- /dev/null +++ b/.changeset/clever-cobras-notice.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Expose `` component to `Astro.fetchContent` diff --git a/.changeset/twenty-ties-protect.md b/.changeset/twenty-ties-protect.md new file mode 100644 index 000000000..075c396d3 --- /dev/null +++ b/.changeset/twenty-ties-protect.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix small issue with Layout components in Astro Markdown files diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 91974a5c7..96e358266 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -262,6 +262,7 @@ function createFetchContentFn(url: URL) { const urlSpec = new URL(spec, url).pathname; return { ...mod.frontmatter, + Content: mod.default, content: mod.metadata, file: new URL(spec, url), url: urlSpec.includes('/pages/') ? urlSpec.replace(/^.*\/pages\//, '/').replace(/(\/index)?\.md$/, '') : undefined, diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index eaf1b3e3b..fadea3f3d 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -42,8 +42,10 @@ ${components ? `import * from '${components}';` : ''} ${setup} const $$content = ${JSON.stringify(content)} ---`; + const imports = `${layout ? `import Layout from '${layout}';` : ''} +${setup}`.trim() // If the user imported "Layout", wrap the content in a Layout - if (/\bLayout\b/.test(prelude)) { + if (/\bLayout\b/.test(imports)) { astroResult = `${prelude}\n\n\n${astroResult}\n\n`; } else { astroResult = `${prelude}\n${astroResult}`; diff --git a/www/src/data/blog-posts/astro-018.md b/www/src/data/blog-posts/astro-018.md index c67367164..a09a9f3b9 100644 --- a/www/src/data/blog-posts/astro-018.md +++ b/www/src/data/blog-posts/astro-018.md @@ -70,4 +70,4 @@ We've been absolutely blown away by the love Astro has recieved in such a short - 2 (TWO!) Astro jobs already posted on Discord! - [GitHub adds support for Astro component syntax highlighting](https://twitter.com/n_moore/status/1417881860051509250) -To learn more about Astro and start building your first site, check out [the Getting Started guide.](https://docs.astro.build) \ No newline at end of file +To learn more about Astro and start building your first site, check out [the Getting Started guide.](https://docs.astro.build) diff --git a/www/src/data/blog-posts/astro-021-preview.md b/www/src/data/blog-posts/astro-021-preview.md index bd9b15502..55ecad1b5 100644 --- a/www/src/data/blog-posts/astro-021-preview.md +++ b/www/src/data/blog-posts/astro-021-preview.md @@ -55,24 +55,24 @@ Our most requested feature ***by far*** has been the ability to use components d Starting in v0.21.0, you can import components inside of your Markdown frontmatter via an optional `setup` script. Once imported, your components can be used anywhere on the page: - -
---
-title: 'Astro 0.21 Early Preview'
-setup: |
-  import Logo from '../components/Logo.astro';
-  import ReactCounter from '../components/Counter.jsx';
----
-
-# Astro now supports components in Markdown!
-
-<Logo />
-
-- Back to markdown here. 
-- Supports static Astro components.
-- Supports dynamic React/Vue/Svelte components!
-
-<ReactCounter start={0} client:load /> 
-
+```astro +--- +title: 'Astro 0.21 Early Preview' +setup: | + import Logo from '../components/Logo.astro'; + import ReactCounter from '../components/Counter.jsx'; +--- + +# Astro now supports components in Markdown! + + + +- Back to markdown here. +- Supports static Astro components. +- Supports dynamic React/Vue/Svelte components! + + +``` This new `setup` script was designed for maximum flexibility. We'll keep improving this API going forward with planned support for default components, default layouts, and markdown component overrides. @@ -92,4 +92,4 @@ If you've read this far, we'd love your help trying out the latest release befor Leave feedback, report bugs, and get involved with Astro's development in our [Discord server](https://astro.build/chat). You can also [follow along](https://twitter.com/astrodotbuild) on Twitter. -Keep your eyes on the sky, đŸ‘©â€đŸš€ Astronaut! \ No newline at end of file +Keep your eyes on the sky, đŸ‘©â€đŸš€ Astronaut! diff --git a/www/src/data/blog-posts/introducing-astro.md b/www/src/data/blog-posts/introducing-astro.md new file mode 100644 index 000000000..fd381e7ea --- /dev/null +++ b/www/src/data/blog-posts/introducing-astro.md @@ -0,0 +1,111 @@ +--- +setup: | + import Shell from '../../components/Shell.astro' + import Note from '../../components/Note.astro' + import BlockQuote from '../../components/BlockQuote.astro' +title: "Introducing Astro: Ship Less JavaScript" +description: | + We're excited to announce Astro as a new way to build static websites and deliver lightning-fast performance without sacrificing a modern developer experience. +publishDate: 'June 8, 2021' +author: 'fred' +heroImage: '/social.jpg' +permalink: 'https://astro.build/blog/introducing-astro' +lang: 'en' +--- +There's a simple secret to building a faster website — *just ship less*. + +Unfortunately, modern web development has been trending in the opposite direction—towards *more.* More JavaScript, more features, more moving parts, and ultimately more complexity needed to keep it all running smoothly. + +Today I'm excited to publicly share Astro: a new kind of static site builder that delivers lightning-fast performance with a modern developer experience. To design Astro, we borrowed the best parts of our favorite tools and then added a few innovations of our own, including: + +- **Bring Your Own Framework (BYOF):** Build your site using React, Svelte, Vue, Preact, web components, or just plain ol' HTML + JavaScript. +- **100% Static HTML, No JS:** Astro renders your entire page to static HTML, removing all JavaScript from your final build by default. +- **On-Demand Components:** Need some JS? Astro can automatically hydrate interactive components when they become visible on the page. If the user never sees it, they never load it. +- **Fully-Featured:** Astro supports TypeScript, Scoped CSS, CSS Modules, Sass, Tailwind, Markdown, MDX, and any of your favorite npm packages. +- **SEO Enabled:** Automatic sitemaps, RSS feeds, pagination and collections take the pain out of SEO and syndication. + +This post marks the first public beta release of Astro. **Missing features and bugs are still to be expected at this early stage.** There are still some months to go before an official 1.0 release, but there are already several fast sites built with Astro in production today. We would love your early feedback as we move towards a v1.0 release later this year. + + + + To learn more about Astro and start building your first site, check out [our Getting Started guide.](https://docs.astro.build) + + + +## Getting Started + +Starting a new project in Astro is easy: + +```shell +# create your project +mkdir new-project-directory +cd new-project-directory +npm init astro + +# install your dependencies +npm install + +# start the dev server and open your browser +npm run dev +``` + + + + To learn more about Astro and start building your first site, check out [our Getting Started guide.](https://docs.astro.build) + + + + +## How Astro Works + +Astro works a lot like a static site generator. If you have ever used Eleventy, Hugo, or Jekyll (or even a server-side web framework like Rails, Laravel, or Django) then you should feel right at home with Astro. + +In Astro, you compose your website using UI components from your favorite JavaScript web framework (React, Svelte, Vue, etc). Astro renders your entire site to static HTML during the build. The result is a fully static website with all JavaScript removed from the final page. No monolithic JavaScript application required, just static HTML that loads as fast as possible in the browser regardless of how many UI components you used to generate it. + +Of course, sometimes client-side JavaScript is inevitable. Image carousels, shopping carts, and auto-complete search bars are just a few examples of things that require some JavaScript to run in the browser. This is where Astro really shines: When a component needs some JavaScript, Astro only loads that one component (and any dependencies). The rest of your site continues to exist as static, lightweight HTML. + +In other full-stack web frameworks this level of per-component optimization would be impossible without loading the entire page in JavaScript, delaying interactivity. In Astro, this kind of [partial hydration](https://addyosmani.com/blog/rehydration/) is built into the tool itself. + +You can even [automatically defer components](https://codepen.io/jonneal/full/ZELvMvw) to only load once they become visible on the page with the `:visible` modifier. + +This new approach to web architecture is called [islands architecture](https://jasonformat.com/islands-architecture/). We didn't coin the term, but Astro may have perfected the technique. We are confident that an HTML-first, JavaScript-only-as-needed approach is the best solution for the majority of content-based websites. + + + + To learn more about Astro and start building your first site, check out [our Getting Started guide.](https://docs.astro.build) + + + +## Embracing the Pit of Success + +
+ + A well-designed system makes it easy to do the right things and annoying (but not impossible) to do the wrong things + +
+ +Poor performance is often framed as a failure of the developer, but we respectfully disagree. In many cases, poor performance is a failure of tooling. It should be difficult to build a slow website. + +Astro's main design principle is to lead developers into what [Rico Mariani](https://twitter.com/ricomariani) dubbed "the pit of success". It is our goal to build every site "fast by default" while also delivering a familiar, modern developer experience. + +By building your site to static HTML by default, Astro makes it difficult (but never impossible 😉) to build a slow site. + +## Long-Term Sustainability + +Astro is built by the team of open source developers behind [Snowpack](https://snowpack.dev) and [Skypack](https://skypack.dev), with additional contributions from the community. + +**Astro is and always will be free.** It is an open source project released under the [MIT license](https://github.com/snowpackjs/astro/blob/main/LICENSE). + +We care deeply about building a more sustainable future for open source software. At the same time, we need to support Astro's development long-term. This requires money (donations alone aren't enough.) + +We're inspired by the early success of projects like [Tailwind](https://tailwindcss.com/), [Rome](https://rome.tools/), [Remix](https://remix.run/), [Ionic](https://ionicframework.com/), and others who are experimenting with long-term financial sustainability on top of Open Source. Over the next year we'll be exploring how we can create a sustainable business to support a 100% free, open source Astro for years to come. + +If your company is as excited about Astro as we are, [we'd love to hear from you.](https://astro.build/chat) + +Finally, I'd like to give a **HUGE** thanks to the 300+ developers who joined our earliest private beta. Your feedback has been essential in shaping Astro into the tool it is today. If you're interested in getting involved (or just following along with development) please [join us on Discord.](https://astro.build/chat) + + + + To learn more about Astro and start building your first site, check out [our Getting Started guide.](https://docs.astro.build) + + diff --git a/www/src/data/blog-posts/netlify-astro-hosting-sponsorship.md b/www/src/data/blog-posts/netlify-astro-hosting-sponsorship.md new file mode 100644 index 000000000..e02e76594 --- /dev/null +++ b/www/src/data/blog-posts/netlify-astro-hosting-sponsorship.md @@ -0,0 +1,34 @@ +--- +setup: | + import Note from '../../components/Note.astro' +title: "Netlify Becomes Astro's Official Hosting Partner" +description: | + We are happy to announce that Netlify has become Astro’s first corporate sponsor and exclusive hosting partner, donating $2,500 each month towards the ongoing open source maintenance and development of Astro. +publishDate: 'September 9, 2021' +heroImage: '/assets/blog/astro-netlify-social.jpg' +lang: 'en' +--- + +We are thrilled to announce that [Netlify](https://www.netlify.com/?utm_campaign=devex-jl&utm_source=astro&utm_medium=blog) has become Astro's first corporate sponsor and official hosting partner, donating [$2,500 each month](https://opencollective.com/astrodotbuild) towards the ongoing open source maintenance and development of Astro. + +Netlify is the company responsible for kicking off the modern [Jamstack](https://jamstack.org/) movement. Today, their hosting + serverless platform is loved by developers around the world. [Astro](http://astro.build/) can build you a blazing-fast website, but you'll always need a great host like Netlify to deliver that snappy experience to your users. + +Here's what Jason told us about Astro: + + + + "Astro is tackling an extremely hard problem: **how do we keep the advantages of powerful frameworks but stop making end users pay the cost of developer experience?** Shipping only HTML and CSS for the vast majority of web content that doesn't need to be dynamic and only including JavaScript when it's actually necessary is a huge win for developers and users alike." + +
+ + — [Jason Lengstorf](https://twitter.com/jlengstorf), VP of Developer Experience, Netlify + +
+ +Astro is honored and excited to have Netlify as our first official corporate sponsor. We are grateful for the support of Jason Lengstorf, Cassidy Williams, and the entire Netlify team for their help and evangelism. It's because of support from companies like Netlify that we are able to receive ongoing maintenance and keep developing Astro in an open, financially-sustainable way. + +Our first integration with Netlify will be to add the ["Deploy with Netlify"](https://www.netlify.com/blog/2016/11/29/introducing-the-deploy-to-netlify-button/) button to our official Astro starter templates. This will make it even easier to create new, hosted Astro websites in just a few clicks. Check out all of our batteries-included starter templates in the brand new [Astro Theme Showcase.](https://docs.astro.build/themes) + +Thanks, Netlify! + +*PS: If your company relies on free, open source software (hint: it almost definitely does!) please [donate to support Astro](https://opencollective.com/astrodotbuild) and other projects like it. You can browse projects accepting funding on [Open Collective](https://opencollective.com/discover), [GitHub Sponsors](https://github.com/sponsors), or by running the `npm fund` command inside of any existing npm project.* diff --git a/www/src/pages/blog/[slug].astro b/www/src/pages/blog/[slug].astro index 2b5d62c1f..fb1af91ab 100644 --- a/www/src/pages/blog/[slug].astro +++ b/www/src/pages/blog/[slug].astro @@ -1,5 +1,4 @@ --- -import { Markdown, Code, Debug } from 'astro/components'; import BaseHead from '../../components/BaseHead.astro'; import BlogHeader from '../../components/BlogHeader.astro'; import BlogPost from '../../components/BlogPost.astro'; @@ -7,16 +6,16 @@ import GoogleAnalytics from '../../components/GoogleAnalytics.astro'; export function getStaticPaths() { const posts = Astro.fetchContent('../../data/blog-posts/*.md'); - return (posts.map(p => ({ - params: {slug: p.file.pathname.split('/').pop().split('.').shift()}, - props: {post: p}, - }))); + return posts.map(p => ({ + params: { slug: p.file.pathname.split('/').pop().split('.').shift() }, + props: { post: p }, + })); } -const {title, author, description, publishDate, heroImage, heroImageAlt, permalink, lang, content} = Astro.props.post; +const { Content, title, author, description, publishDate, heroImage, heroImageAlt, permalink, lang } = Astro.props.post; --- - + @@ -24,7 +23,7 @@ const {title, author, description, publishDate, heroImage, heroImageAlt, permali - {content.html} + diff --git a/www/src/pages/blog/introducing-astro.astro b/www/src/pages/blog/introducing-astro.astro deleted file mode 100644 index 04238e710..000000000 --- a/www/src/pages/blog/introducing-astro.astro +++ /dev/null @@ -1,120 +0,0 @@ ---- -import { Markdown } from 'astro/components'; -import BaseHead from '../../components/BaseHead.astro'; -import BlogHeader from '../../components/BlogHeader.astro'; -import BlogPost from '../../components/BlogPost.astro'; -import BlockQuote from '../../components/BlockQuote.astro'; -import Note from '../../components/Note.astro'; -import Shell from '../../components/Shell.astro'; - -let title = 'Introducing Astro: Ship Less JavaScript'; -let description = `We're excited to announce Astro as a new way to build static websites and deliver lightning-fast performance without sacrificing a modern developer experience.`; -let publishDate = 'June 8, 2021'; -let author = 'fred'; -let heroImage = '/social.jpg'; -let permalink = 'https://astro.build/blog/introducing-astro'; -let lang = 'en'; ---- - - - - - - - - - - - - There's a simple secret to building a faster website — *just ship less*. - - Unfortunately, modern web development has been trending in the opposite direction—towards *more.* More JavaScript, more features, more moving parts, and ultimately more complexity needed to keep it all running smoothly. - - Today I'm excited to publicly share Astro: a new kind of static site builder that delivers lightning-fast performance with a modern developer experience. To design Astro, we borrowed the best parts of our favorite tools and then added a few innovations of our own, including: - - - **Bring Your Own Framework (BYOF):** Build your site using React, Svelte, Vue, Preact, web components, or just plain ol' HTML + JavaScript. - - **100% Static HTML, No JS:** Astro renders your entire page to static HTML, removing all JavaScript from your final build by default. - - **On-Demand Components:** Need some JS? Astro can automatically hydrate interactive components when they become visible on the page. If the user never sees it, they never load it. - - **Fully-Featured:** Astro supports TypeScript, Scoped CSS, CSS Modules, Sass, Tailwind, Markdown, MDX, and any of your favorite npm packages. - - **SEO Enabled:** Automatic sitemaps, RSS feeds, pagination and collections take the pain out of SEO and syndication. - - This post marks the first public beta release of Astro. **Missing features and bugs are still to be expected at this early stage.** There are still some months to go before an official 1.0 release, but there are already several fast sites built with Astro in production today. We would love your early feedback as we move towards a v1.0 release later this year. - - - To learn more about Astro and start building your first site, check out [our Getting Started guide.](https://docs.astro.build) - - - ## Getting Started - - Starting a new project in Astro is easy: - - - - - To learn more about Astro and start building your first site, check out [our Getting Started guide.](https://docs.astro.build) - - - - ## How Astro Works - - Astro works a lot like a static site generator. If you have ever used Eleventy, Hugo, or Jekyll (or even a server-side web framework like Rails, Laravel, or Django) then you should feel right at home with Astro. - - In Astro, you compose your website using UI components from your favorite JavaScript web framework (React, Svelte, Vue, etc). Astro renders your entire site to static HTML during the build. The result is a fully static website with all JavaScript removed from the final page. No monolithic JavaScript application required, just static HTML that loads as fast as possible in the browser regardless of how many UI components you used to generate it. - - Of course, sometimes client-side JavaScript is inevitable. Image carousels, shopping carts, and auto-complete search bars are just a few examples of things that require some JavaScript to run in the browser. This is where Astro really shines: When a component needs some JavaScript, Astro only loads that one component (and any dependencies). The rest of your site continues to exist as static, lightweight HTML. - - In other full-stack web frameworks this level of per-component optimization would be impossible without loading the entire page in JavaScript, delaying interactivity. In Astro, this kind of [partial hydration](https://addyosmani.com/blog/rehydration/) is built into the tool itself. - - You can even [automatically defer components](https://codepen.io/jonneal/full/ZELvMvw) to only load once they become visible on the page with the `:visible` modifier. - - This new approach to web architecture is called [islands architecture](https://jasonformat.com/islands-architecture/). We didn't coin the term, but Astro may have perfected the technique. We are confident that an HTML-first, JavaScript-only-as-needed approach is the best solution for the majority of content-based websites. - - - To learn more about Astro and start building your first site, check out [our Getting Started guide.](https://docs.astro.build) - - - ## Embracing the Pit of Success - -
- A well-designed system makes it easy to do the right things and annoying (but not impossible) to do the wrong things -
- - Poor performance is often framed as a failure of the developer, but we respectfully disagree. In many cases, poor performance is a failure of tooling. It should be difficult to build a slow website. - - Astro's main design principle is to lead developers into what [Rico Mariani](https://twitter.com/ricomariani) dubbed "the pit of success". It is our goal to build every site "fast by default" while also delivering a familiar, modern developer experience. - - By building your site to static HTML by default, Astro makes it difficult (but never impossible 😉) to build a slow site. - - ## Long-Term Sustainability - - Astro is built by the team of open source developers behind [Snowpack](https://snowpack.dev) and [Skypack](https://skypack.dev), with additional contributions from the community. - - **Astro is and always will be free.** It is an open source project released under the [MIT license](https://github.com/snowpackjs/astro/blob/main/LICENSE). - - We care deeply about building a more sustainable future for open source software. At the same time, we need to support Astro's development long-term. This requires money (donations alone aren't enough.) - - We're inspired by the early success of projects like [Tailwind](https://tailwindcss.com/), [Rome](https://rome.tools/), [Remix](https://remix.run/), [Ionic](https://ionicframework.com/), and others who are experimenting with long-term financial sustainability on top of Open Source. Over the next year we'll be exploring how we can create a sustainable business to support a 100% free, open source Astro for years to come. - - If your company is as excited about Astro as we are, [we'd love to hear from you.](https://astro.build/chat) - - Finally, I'd like to give a **HUGE** thanks to the 300+ developers who joined our earliest private beta. Your feedback has been essential in shaping Astro into the tool it is today. If you're interested in getting involved (or just following along with development) please [join us on Discord.](https://astro.build/chat) - - - To learn more about Astro and start building your first site, check out [our Getting Started guide.](https://docs.astro.build) - -
-
- - - diff --git a/www/src/pages/blog/netlify-astro-hosting-sponsorship.astro b/www/src/pages/blog/netlify-astro-hosting-sponsorship.astro deleted file mode 100644 index a88a5a533..000000000 --- a/www/src/pages/blog/netlify-astro-hosting-sponsorship.astro +++ /dev/null @@ -1,59 +0,0 @@ ---- -import { Markdown, Prism } from 'astro/components'; -import BlogHead from '../../components/BlogHead.astro'; -import BlogHeader from '../../components/BlogHeader.astro'; -import BlogPost from '../../components/BlogPost.astro'; -import BlockQuote from '../../components/BlockQuote.astro'; -import GoogleAnalytics from '../../components/GoogleAnalytics.astro'; -import Note from '../../components/Note.astro'; -import Shell from '../../components/Shell.astro'; -import { mediaQueries } from '../../config.ts'; - -let title = "Netlify Becomes Astro's Official Hosting Partner"; -let description = `We are happy to announce that Netlify has become Astro’s first corporate sponsor and exclusive hosting partner, donating $2,500 each month towards the ongoing open source maintenance and development of Astro.`; -let publishDate = 'September 9, 2021'; -let heroImage = '/assets/blog/astro-netlify-social.jpg'; -let lang = 'en'; ---- - - - - - - - - - - - - - We are thrilled to announce that [Netlify](https://www.netlify.com/?utm_campaign=devex-jl&utm_source=astro&utm_medium=blog - ) has become Astro's first corporate sponsor and official hosting partner, donating [$2,500 each month](https://opencollective.com/astrodotbuild) towards the ongoing open source maintenance and development of Astro. - - Netlify is the company responsible for kicking off the modern [Jamstack](https://jamstack.org/) movement. Today, their hosting + serverless platform is loved by developers around the world. [Astro](http://astro.build/) can build you a blazing-fast website, but you'll always need a great host like Netlify to deliver that snappy experience to your users. - - Here's what Jason told us about Astro: - - - - "Astro is tackling an extremely hard problem: **how do we keep the advantages of powerful frameworks but stop making end users pay the cost of developer experience?** Shipping only HTML and CSS for the vast majority of web content that doesn't need to be dynamic and only including JavaScript when it's actually necessary is a huge win for developers and users alike." -
-- [Jason Lengstorf](https://twitter.com/jlengstorf), VP of Developer Experience, Netlify -
- - Astro is honored and excited to have Netlify as our first official corporate sponsor. We are grateful for the support of Jason Lengstorf, Cassidy Williams, and the entire Netlify team for their help and evangelism. It's because of support from companies like Netlify that we are able to receive ongoing maintenance and keep developing Astro in an open, financially-sustainable way. - - Our first integration with Netlify will be to add the ["Deploy with Netlify"](https://www.netlify.com/blog/2016/11/29/introducing-the-deploy-to-netlify-button/) button to our official Astro starter templates. This will make it even easier to create new, hosted Astro websites in just a few clicks. Check out all of our batteries-included starter templates in the brand new [Astro Theme Showcase.](https://docs.astro.build/themes) - - Thanks, Netlify! - - *PS: If your company relies on free, open source software (hint: it almost definitely does!) please [donate to support Astro](https://opencollective.com/astrodotbuild) and other projects like it. You can browse projects accepting funding on [Open Collective](https://opencollective.com/discover), [GitHub Sponsors](https://github.com/sponsors), or by running the `npm fund` command inside of any existing npm project.* -
-
- - - -