Skip to content

Commit

Permalink
Add warnings on markdown deprecations (#4046)
Browse files Browse the repository at this point in the history
* Warn when using content.astro.headers

* Warn when using setup without the legacy flag enabled

* Adds a changeset
  • Loading branch information
matthewp authored Jul 25, 2022
1 parent f9e8e72 commit c811be4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-seas-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Adds warnings for legacy markdown behavior
2 changes: 1 addition & 1 deletion packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function createVite(
// the build to run very slow as the filewatcher is triggered often.
mode === 'dev' && astroViteServerPlugin({ config: astroConfig, logging }),
envVitePlugin({ config: astroConfig }),
markdownVitePlugin({ config: astroConfig }),
markdownVitePlugin({ config: astroConfig, logging }),
htmlVitePlugin(),
jsxVitePlugin({ config: astroConfig, logging }),
astroPostprocessVitePlugin({ config: astroConfig }),
Expand Down
21 changes: 19 additions & 2 deletions packages/astro/src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import matter from 'gray-matter';
import { fileURLToPath } from 'url';
import type { Plugin } from 'vite';
import type { AstroConfig } from '../@types/astro';
import type { LogOptions } from '../core/logger/core.js';
import { pagesVirtualModuleId } from '../core/app/index.js';
import { collectErrorMetadata } from '../core/errors.js';
import { resolvePages } from '../core/util.js';
Expand All @@ -14,9 +15,11 @@ import { getViteTransform, TransformHook } from '../vite-plugin-astro/styles.js'
import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types';
import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js';
import { getFileInfo } from '../vite-plugin-utils/index.js';
import { warn } from '../core/logger/core.js';

interface AstroPluginOptions {
config: AstroConfig;
logging: LogOptions;
}

const MARKDOWN_IMPORT_FLAG = '?mdImport';
Expand All @@ -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.
// Both end up connecting a `load()` hook to the Astro compiler, and share some copy-paste
// 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) {
if (filename.startsWith('/@fs')) {
filename = filename.slice('/@fs'.length);
Expand Down Expand Up @@ -170,6 +173,12 @@ export default function markdown({ config }: AstroPluginOptions): Plugin {
content.astro = metadata;
content.url = getFileInfo(id, config).fileUrl;
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 = `---
import Slugger from 'github-slugger';
${layout ? `import Layout from '${layout}';` : ''}
Expand All @@ -188,8 +197,16 @@ const $$content = ${JSON.stringify(
: // Avoid stripping "setup" and "components"
// in plain MD mode
{ ...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}';` : ''}
${isAstroFlavoredMd ? setup : ''}`.trim();

Expand Down

0 comments on commit c811be4

Please sign in to comment.