summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2022-07-25 15:14:53 -0400
committerGravatar GitHub <noreply@github.com> 2022-07-25 15:14:53 -0400
commitc811be49abf17b151e04b9a63126267065f53b3f (patch)
tree3caf738392e9f233a4851e6fb396e161c22289e2
parentf9e8e72a489495a6cd01fde771e298460493708f (diff)
downloadastro-c811be49abf17b151e04b9a63126267065f53b3f.tar.gz
astro-c811be49abf17b151e04b9a63126267065f53b3f.tar.zst
astro-c811be49abf17b151e04b9a63126267065f53b3f.zip
Add warnings on markdown deprecations (#4046)
* Warn when using content.astro.headers * Warn when using setup without the legacy flag enabled * Adds a changeset
-rw-r--r--.changeset/large-seas-drum.md5
-rw-r--r--packages/astro/src/core/create-vite.ts2
-rw-r--r--packages/astro/src/vite-plugin-markdown/index.ts21
3 files changed, 25 insertions, 3 deletions
diff --git a/.changeset/large-seas-drum.md b/.changeset/large-seas-drum.md
new file mode 100644
index 000000000..81cdc898d
--- /dev/null
+++ b/.changeset/large-seas-drum.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Adds warnings for legacy markdown behavior
diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts
index 35029b7fc..0855112ea 100644
--- a/packages/astro/src/core/create-vite.ts
+++ b/packages/astro/src/core/create-vite.ts
@@ -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 }),
diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts
index 8b5c58425..f48168521 100644
--- a/packages/astro/src/vite-plugin-markdown/index.ts
+++ b/packages/astro/src/vite-plugin-markdown/index.ts
@@ -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';
@@ -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';
@@ -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);
@@ -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}';` : ''}
@@ -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();