import { parseFrontmatter } from '@astrojs/markdown-remark'; import type { Options as AcornOpts } from 'acorn'; import { parse } from 'acorn'; import type { AstroConfig, AstroIntegrationLogger, SSRError } from 'astro'; import { bold } from 'kleur/colors'; import type { MdxjsEsm } from 'mdast-util-mdx'; import type { PluggableList } from 'unified'; function appendForwardSlash(path: string) { return path.endsWith('/') ? path : path + '/'; } export interface FileInfo { fileId: string; fileUrl: string; } /** @see 'vite-plugin-utils' for source */ export function getFileInfo(id: string, config: AstroConfig): FileInfo { const sitePathname = appendForwardSlash( config.site ? new URL(config.base, config.site).pathname : config.base, ); // Try to grab the file's actual URL let url: URL | undefined = undefined; try { url = new URL(`file://${id}`); } catch {} const fileId = id.split('?')[0]; let fileUrl: string; const isPage = fileId.includes('/pages/'); if (isPage) { fileUrl = fileId.replace(/^.*?\/pages\//, sitePathname).replace(/(?:\/index)?\.mdx$/, ''); } else if (url?.pathname.startsWith(config.root.pathname)) { fileUrl = url.pathname.slice(config.root.pathname.length); } else { fileUrl = fileId; } if (fileUrl && config.trailingSlash === 'always') { fileUrl = appendForwardSlash(fileUrl); } return { fileId, fileUrl }; } /** * Match YAML exception handling from Astro core errors * @see 'astro/src/core/errors.ts' */ export function safeParseFrontmatter(code: string, id: string) { try { return parseFrontmatter(code, { frontmatter: 'empty-with-spaces' }); } catch (e: any) { if (e.name === 'YAMLException') { const err: SSRError = e; err.id = id; err.loc = { file: e.id, line: e.mark.line + 1, column: e.mark.column }; err.message = e.reason; throw err; } else { throw e; } } } export function jsToTreeNode( jsString: string, acornOpts: AcornOpts = { ecmaVersion: 'latest', sourceType: 'module', }, ): MdxjsEsm { return { type: 'mdxjsEsm', value: '', data: { // @ts-expect-error `parse` return types is incompatible but it should work in runtime estree: { ...parse(jsString, acornOpts), type: 'Program', sourceType: 'module', }, }, }; } export function ignoreStringPlugins(plugins: any[], logger: AstroIntegrationLogger): PluggableList { let validPlugins: PluggableList = []; let hasInvalidPlugin = false; for (const plugin of plugins) { if (typeof plugin === 'string') { logger.warn(`${bold(plugin)} not applied.`); hasInvalidPlugin = true; } else if (Array.isArray(plugin) && typeof plugin[0] === 'string') { logger.warn(`${bold(plugin[0])} not applied.`); hasInvalidPlugin = true; } else { validPlugins.push(plugin); } } if (hasInvalidPlugin) { logger.warn( `To inherit Markdown plugins in MDX, please use explicit imports in your config instead of "strings." See Markdown docs: https://docs.astro.build/en/guides/markdown-content/#markdown-plugins`, ); } return validPlugins; } dling'>densities-handling Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/examples/framework-svelte/src/env.d.ts (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-11-27Remove support for simple objects in endpoints (#9181)Gravatar Bjorn Lu 56-529/+206
2023-11-28Remove shiki lang path property support (#9196)Gravatar Bjorn Lu 7-427/+22
2023-11-28Remove deprecated features from Astro 3.0 (#9168)Gravatar Bjorn Lu 47-398/+95
2023-11-28Remove deprecated markdown-remark APIs (#9182)Gravatar Bjorn Lu 4-59/+7
2023-11-27[ci] release (#9180)astro@3.6.1Gravatar Houston (Bot) 32-65/+63
2023-11-24Remove vercel deprecated analytics option (#9184)Gravatar Bjorn Lu 3-30/+12
2023-11-24[ci] formatGravatar Guspan Tanadi 1-2/+1
2023-11-24style: highlight markdown Tip Note section CONTRIBUTING (#9123)Gravatar Guspan Tanadi 1-5/+7
2023-11-23fix scroll restoration issue on webKit browsers (#9186)Gravatar Martin Trapp 2-1/+7
2023-11-23fix(middleware): rename internal middleware id (#9173)Gravatar Arsh 2-1/+6
2023-11-23fix: Changelog formatting for 3.6.0 View Transition events (#9176)Gravatar Martin Trapp 1-3/+3
2023-11-22[ci] formatGravatar Eva Decker 1-3/+3
2023-11-22Fix View Transitions code block formatting (#9174)Gravatar Eva Decker 1-3/+3
2023-11-22Rename entryPoint to entrypoint (#9161)Gravatar Bjorn Lu 14-26/+38
2023-11-22Fix esbuild warning for local dev (#9160)Gravatar Bjorn Lu 1-1/+1
2023-11-22[ci] release (#9165)astro@3.6.0Gravatar Houston (Bot) 34-90/+83