astro 2.0.0-beta.0
Major Changes
-
#5687
e2019be6fThanks @bholmesdev! - Give remark and rehype plugins access to user frontmatter via frontmatter injection. This meansdata.astro.frontmatteris now the complete Markdown or MDX document's frontmatter, rather than an empty object.This allows plugin authors to modify existing frontmatter, or compute new properties based on other properties. For example, say you want to compute a full image URL based on an
imageSrcslug in your document frontmatter:export function remarkInjectSocialImagePlugin() { return function (tree, file) { const { frontmatter } = file.data.astro; frontmatter.socialImageSrc = new URL(frontmatter.imageSrc, 'https://my-blog.com/').pathname; }; }Content Collections - new
remarkPluginFrontmatterpropertyWe have changed inject frontmatter to modify frontmatter in our docs to improve discoverability. This is based on support forum feedback, where "injection" is rarely the term used.
To reflect this, the
injectedFrontmatterproperty has been renamed toremarkPluginFrontmatter. This should clarify this plugin is still separate from thedataexport Content Collections expose today.Migration instructions
Plugin authors should now check for user frontmatter when applying defaults.
For example, say a remark plugin wants to apply a default
titleif none is present. Add a conditional to check if the property is present, and update if none exists:export function remarkInjectTitlePlugin() { return function (tree, file) { const { frontmatter } = file.data.astro; + if (!frontmatter.title) { frontmatter.title = 'Default title'; + } } }This differs from previous behavior, where a Markdown file's frontmatter would always override frontmatter injected via remark or reype.
-
#5728
8fb28648fThanks @natemoo-re! - The previously experimental features--experimental-error-overlayand--experimental-prerender, both added in v1.7.0, are now the default.You'll notice that the error overlay during
astro devhas a refreshed visual design and provides more context for your errors.The
prerenderfeature is now enabled by default when usingoutput: 'server'. To prerender a particular page, addexport const prerender = trueto your frontmatter.Warning Integration authors that previously relied on the exact structure of Astro's v1.0 build output may notice some changes to our output file structure. Please test your integrations to ensure compatability. Users that have configured a custom
vite.build.rollupOptions.output.chunkFileNamesshould ensure that their Astro project is configured as an ESM Node project. Either include"type": "module"in your rootpackage.jsonfile or use the.mjsextension forchunkFileNames. -
#5716
dd56c1941Thanks @bluwy! - Remove MDX Fragment hack. This was used by@astrojs/mdxto access theFragmentcomponent, but isn't require anymore since@astrojs/mdxv0.12.1. -
#5685
f6cf92b48Thanks @bluwy! - Upgrade to Vite 4. Please see its migration guide for more information. -
#5724
16c7d0bfdThanks @bluwy! - Remove outdated Vue info log. RemovetoStringsupport forRenderTemplateResult. -
#5684
a9c292026Thanks @bholmesdev! - Refine Markdown and MDX configuration options for ease-of-use.Markdown
- Remove
remark-smartypantsfrom Astro's default Markdown plugins. - Replace the
extendDefaultPluginsoption with a simplifiedgfmboolean. This is enabled by default, and can be disabled to remove GitHub-Flavored Markdown. - Ensure GitHub-Flavored Markdown is applied whether or not custom
remarkPluginsorrehypePluginsare configured. If you want to apply custom plugins and remove GFM, manually setgfm: falsein your config.
MDX
- Support all Markdown configuration options (except
drafts) from your MDX integration config. This includessyntaxHighlightingandshikiConfigoptions to further customize the MDX renderer. - Simplify
extendDefaultsto anextendMarkdownConfigoption. MDX options will default to their equivalent in your Markdown config. By settingextendMarkdownConfigto false, you can "eject" to set your own syntax highlighting, plugins, and more.
Migration
To preserve your existing Markdown and MDX setup, you may need some configuration changes:
Smartypants manual installation
Smartypants has been removed from Astro's default setup. If you rely on this plugin, install
remark-smartypantsand apply to yourastro.config.*:// astro.config.mjs import { defineConfig } from 'astro/config'; + import smartypants from 'remark-smartypants'; export default defineConfig({ markdown: { + remarkPlugins: [smartypants], } });Migrate
extendDefaultPluginstogfmYou may have disabled Astro's built-in plugins (GitHub-Flavored Markdown and Smartypants) with the
extendDefaultPluginsoption. Since Smartypants has been removed, this has been renamed togfm.// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ markdown: { - extendDefaultPlugins: false, + gfm: false, } });Additionally, applying remark and rehype plugins no longer disables
gfm. You will need to opt-out manually by settinggfmtofalse.Migrate MDX's
extendPluginstoextendMarkdownConfigYou may have used the
extendPluginsoption to manage plugin defaults in MDX. This has been replaced by 2 flags:extendMarkdownConfig(trueby default) to toggle Markdown config inheritance. This replaces theextendPlugins: 'markdown'option.gfm(trueby default) to toggle GitHub-Flavored Markdown in MDX. This replaces theextendPlugins: 'defaults'option.
- Remove
-
#5707
5eba34fccThanks @bluwy! - Remove deprecatedAstroglobal APIs, includingAstro.resolve,Astro.fetchContent, andAstro.canonicalURL.Astro.resolveYou can resolve asset paths using
importinstead. For example:--- import 'style.css'; import imageUrl from './image.png'; --- <img src={imageUrl} />See the v0.25 migration guide for more information.
Astro.fetchContentUse
Astro.globinstead to fetch markdown files, or migrate to the Content Collections feature.let allPosts = await Astro.glob('./posts/*.md');Astro.canonicalURLUse
Astro.urlinstead to construct the canonical URL.const canonicalURL = new URL(Astro.url.pathname, Astro.site); -
#5707
5eba34fccThanks @bluwy! - RemovebuildConfigoption parameter from integrationastro:build:starthook in favour of thebuild.configoption in theastro:config:setuphook.export default function myIntegration() { return { name: 'my-integration', hooks: { 'astro:config:setup': ({ updateConfig }) => { updateConfig({ build: { client: '...', server: '...', serverEntry: '...', }, }); }, }, }; }