Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warnings on markdown deprecations #4046

Merged
merged 3 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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