šæ Minor Changes
-
#12047
21b5e80Thanks @rgodha24! - Adds a new optionalparserproperty to the built-infile()loader for content collections to support additional file types such astomlandcsv.The
file()loader now accepts a second argument that defines aparserfunction. This allows you to specify a custom parser (e.g.toml.parseorcsv-parse) to create a collection from a fileās contents. Thefile()loader will automatically detect and parse JSON and YAML files (based on their file extension) with no need for aparser.This works with any type of custom file formats including
csvandtoml. The following example defines a content collectiondogsusing a.tomlfile.[[dogs]]id = "..."age = "..."[[dogs]]id = "..."age = "..."After importing TOMLās parser, you can load the
dogscollection into your project by passing both a file path andparserto thefile()loader.import { defineCollection } from "astro:content"import { file } from "astro/loaders"import { parse as parseToml } from "toml"const dogs = defineCollection({loader: file("src/data/dogs.toml", { parser: (text) => parseToml(text).dogs }),schema: /* ... */})// it also works with CSVs!import { parse as parseCsv } from "csv-parse/sync";const cats = defineCollection({loader: file("src/data/cats.csv", { parser: (text) => parseCsv(text, { columns: true, skipEmptyLines: true })})});The
parserargument also allows you to load a single collection from a nested JSON document. For example, this JSON file contains multiple collections:{ "dogs": [{}], "cats": [{}] }You can seperate these collections by passing a custom
parserto thefile()loader like so:const dogs = defineCollection({loader: file('src/data/pets.json', { parser: (text) => JSON.parse(text).dogs }),});const cats = defineCollection({loader: file('src/data/pets.json', { parser: (text) => JSON.parse(text).cats }),});And it continues to work with maps of
idtodatabubbles:breed: 'Goldfish'age: 2finn:breed: 'Betta'age: 1const fish = defineCollection({loader: file('src/data/fish.yaml'),schema: z.object({ breed: z.string(), age: z.number() }),}); -
#12071
61d248eThanks @Princesseuh! -astro addno longer automatically setsoutput: 'server'. Since the default value of output now allows for server-rendered pages, it no longer makes sense to default to full server builds when you add an adapter -
#11963
0a1036eThanks @florian-lefebvre! - Adds a newcreateCodegenDir()function to theastro:config:setuphook in the Integrations APIIn 4.14, we introduced the
injectTypesutility on theastro:config:donehook. It can create.d.tsfiles and make their types available to userās projects automatically. Under the hood, it creates a file in<root>/.astro/integrations/<normalized_integration_name>.While the
.astrodirectory has always been the preferred place to write code generated files, it has also been prone to mistakes. For example, you can write a.astro/types.d.tsfile, breaking Astro types. Or you can create a file that overrides a file created by another integration.In this release,
<root>/.astro/integrations/<normalized_integration_name>can now be retrieved in theastro:config:setuphook by callingcreateCodegenDir(). It allows you to have a dedicated folder, avoiding conflicts with another integration or Astro itself. This directory is created by calling this function so itās safe to write files to it directly:import { writeFileSync } from 'node:fs';const integration = {name: 'my-integration',hooks: {'astro:config:setup': ({ createCodegenDir }) => {const codegenDir = createCodegenDir();writeFileSync(new URL('cache.json', codegenDir), '{}', 'utf-8');},},}; -
#12081
8679954Thanks @florian-lefebvre! - Removes the experimentalcontentCollectionsCacheintroduced in3.5.0.Astro Content Layer API independently solves some of the caching and performance issues with legacy content collections that this strategy attempted to address. This feature has been replaced with continued work on improvements to the content layer. If you were using this experimental feature, you must now remove the flag from your Astro config as it no longer exists:
export default defineConfig({experimental: {contentCollectionsCache: true}})The
cacheManifestboolean argument is no longer passed to theastro:build:doneintegration hook:const integration = {name: "my-integration",hooks: {"astro:build:done": ({cacheManifest,logger}) => {}}}
š Patch Changes
-
#12073
acf264dThanks @bluwy! - Replacesorawithyocto-spinner -
#12075
a19530eThanks @bluwy! - Parses frontmatter ourselves -
#12070
9693ad4Thanks @ematipico! - Fixes an issue where the check origin middleware was incorrectly injected when the build output was"static" -
Updated dependencies [
a19530e]:- @astrojs/markdown-remark@6.0.0-beta.2