Add warnings on markdown deprecations (#4046)
* Warn when using content.astro.headers * Warn when using setup without the legacy flag enabled * Adds a changeset
This commit is contained in:
parent
f9e8e72a48
commit
c811be49ab
3 changed files with 25 additions and 3 deletions
5
.changeset/large-seas-drum.md
Normal file
5
.changeset/large-seas-drum.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Adds warnings for legacy markdown behavior
|
|
@ -73,7 +73,7 @@ export async function createVite(
|
||||||
// the build to run very slow as the filewatcher is triggered often.
|
// the build to run very slow as the filewatcher is triggered often.
|
||||||
mode === 'dev' && astroViteServerPlugin({ config: astroConfig, logging }),
|
mode === 'dev' && astroViteServerPlugin({ config: astroConfig, logging }),
|
||||||
envVitePlugin({ config: astroConfig }),
|
envVitePlugin({ config: astroConfig }),
|
||||||
markdownVitePlugin({ config: astroConfig }),
|
markdownVitePlugin({ config: astroConfig, logging }),
|
||||||
htmlVitePlugin(),
|
htmlVitePlugin(),
|
||||||
jsxVitePlugin({ config: astroConfig, logging }),
|
jsxVitePlugin({ config: astroConfig, logging }),
|
||||||
astroPostprocessVitePlugin({ config: astroConfig }),
|
astroPostprocessVitePlugin({ config: astroConfig }),
|
||||||
|
|
|
@ -6,6 +6,7 @@ import matter from 'gray-matter';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import type { Plugin } from 'vite';
|
import type { Plugin } from 'vite';
|
||||||
import type { AstroConfig } from '../@types/astro';
|
import type { AstroConfig } from '../@types/astro';
|
||||||
|
import type { LogOptions } from '../core/logger/core.js';
|
||||||
import { pagesVirtualModuleId } from '../core/app/index.js';
|
import { pagesVirtualModuleId } from '../core/app/index.js';
|
||||||
import { collectErrorMetadata } from '../core/errors.js';
|
import { collectErrorMetadata } from '../core/errors.js';
|
||||||
import { resolvePages } from '../core/util.js';
|
import { resolvePages } from '../core/util.js';
|
||||||
|
@ -14,9 +15,11 @@ import { getViteTransform, TransformHook } from '../vite-plugin-astro/styles.js'
|
||||||
import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types';
|
import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types';
|
||||||
import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js';
|
import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js';
|
||||||
import { getFileInfo } from '../vite-plugin-utils/index.js';
|
import { getFileInfo } from '../vite-plugin-utils/index.js';
|
||||||
|
import { warn } from '../core/logger/core.js';
|
||||||
|
|
||||||
interface AstroPluginOptions {
|
interface AstroPluginOptions {
|
||||||
config: AstroConfig;
|
config: AstroConfig;
|
||||||
|
logging: LogOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MARKDOWN_IMPORT_FLAG = '?mdImport';
|
const MARKDOWN_IMPORT_FLAG = '?mdImport';
|
||||||
|
@ -34,7 +37,7 @@ function safeMatter(source: string, id: string) {
|
||||||
// TODO: Clean up some of the shared logic between this Markdown plugin and the Astro plugin.
|
// TODO: Clean up some of the shared logic between this Markdown plugin and the Astro plugin.
|
||||||
// Both end up connecting a `load()` hook to the Astro compiler, and share some copy-paste
|
// Both end up connecting a `load()` hook to the Astro compiler, and share some copy-paste
|
||||||
// logic in how that is done.
|
// logic in how that is done.
|
||||||
export default function markdown({ config }: AstroPluginOptions): Plugin {
|
export default function markdown({ config, logging }: AstroPluginOptions): Plugin {
|
||||||
function normalizeFilename(filename: string) {
|
function normalizeFilename(filename: string) {
|
||||||
if (filename.startsWith('/@fs')) {
|
if (filename.startsWith('/@fs')) {
|
||||||
filename = filename.slice('/@fs'.length);
|
filename = filename.slice('/@fs'.length);
|
||||||
|
@ -170,6 +173,12 @@ export default function markdown({ config }: AstroPluginOptions): Plugin {
|
||||||
content.astro = metadata;
|
content.astro = metadata;
|
||||||
content.url = getFileInfo(id, config).fileUrl;
|
content.url = getFileInfo(id, config).fileUrl;
|
||||||
content.file = filename;
|
content.file = filename;
|
||||||
|
|
||||||
|
// Warn when attempting to use setup without the legacy flag
|
||||||
|
if(setup && !isAstroFlavoredMd) {
|
||||||
|
warn(logging, 'markdown', `The setup: property in frontmatter only works with the legacy.astroFlavoredMarkdown flag enabled.`);
|
||||||
|
}
|
||||||
|
|
||||||
const prelude = `---
|
const prelude = `---
|
||||||
import Slugger from 'github-slugger';
|
import Slugger from 'github-slugger';
|
||||||
${layout ? `import Layout from '${layout}';` : ''}
|
${layout ? `import Layout from '${layout}';` : ''}
|
||||||
|
@ -188,8 +197,16 @@ const $$content = ${JSON.stringify(
|
||||||
: // Avoid stripping "setup" and "components"
|
: // Avoid stripping "setup" and "components"
|
||||||
// in plain MD mode
|
// in plain MD mode
|
||||||
{ ...content, setup, components }
|
{ ...content, setup, components }
|
||||||
)}
|
)};
|
||||||
|
|
||||||
|
Object.defineProperty($$content.astro, 'headers', {
|
||||||
|
get() {
|
||||||
|
console.warn('content.astro.headers has been removed and replaced with content.astro.headings.');
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
---`;
|
---`;
|
||||||
|
|
||||||
const imports = `${layout ? `import Layout from '${layout}';` : ''}
|
const imports = `${layout ? `import Layout from '${layout}';` : ''}
|
||||||
${isAstroFlavoredMd ? setup : ''}`.trim();
|
${isAstroFlavoredMd ? setup : ''}`.trim();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue