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

Fix: Netlify edge deployment when using markdown #3612

Merged
merged 11 commits into from
Jun 17, 2022
7 changes: 7 additions & 0 deletions .changeset/fluffy-hounds-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'astro': patch
'@astrojs/netlify': patch
'@astrojs/markdown-remark': patch
---

Fix: "vpath" import error when building for netlify edge
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default function markdown({ config }: AstroPluginOptions): Plugin {
const { layout = '', components = '', setup = '', ...content } = frontmatter;
content.astro = metadata;
const prelude = `---
import { slug as $$slug } from '@astrojs/markdown-remark';
import { slug as $$slug } from '@astrojs/markdown-remark/ssr-utils';
${layout ? `import Layout from '${layout}';` : ''}
${components ? `import * from '${components}';` : ''}
${hasInjectedScript ? `import '${PAGE_SSR_SCRIPT_ID}';` : ''}
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test-fn": "mocha --exit --timeout 20000 test/functions/",
"test-edge": "deno test --allow-run --allow-read --allow-net ./test/edge-functions/",
"test": "npm run test-fn"
"test": "npm run test-fn && npm run test-edge"
},
"dependencies": {
"@astrojs/webapi": "^0.12.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/netlify/src/netlify-edge-functions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SSRManifest } from 'astro';
import { App } from 'astro/app';
import './edge-shim.js';
import type { SSRManifest } from 'astro';
import { App } from 'astro/app';

export function createExports(manifest: SSRManifest) {
const app = new App(manifest);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Hey there!
---

# {frontmatter.title}!

It's a markdown file!
3 changes: 2 additions & 1 deletion packages/markdown/remark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"homepage": "https://astro.build",
"main": "./dist/index.js",
"exports": {
".": "./dist/index.js"
".": "./dist/index.js",
"./ssr-utils": "./dist/ssr-utils.js"
},
"scripts": {
"prepublish": "pnpm build",
Expand Down
6 changes: 0 additions & 6 deletions packages/markdown/remark/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import scopedStyles from './remark-scoped-styles.js';
import remarkShiki from './remark-shiki.js';
import remarkUnwrap from './remark-unwrap.js';

import Slugger from 'github-slugger';
import rehypeRaw from 'rehype-raw';
import rehypeStringify from 'rehype-stringify';
import markdown from 'remark-parse';
Expand All @@ -26,11 +25,6 @@ export * from './types.js';
export const DEFAULT_REMARK_PLUGINS = ['remark-gfm', 'remark-smartypants'];
export const DEFAULT_REHYPE_PLUGINS = [];

const slugger = new Slugger();
export function slug(value: string): string {
return slugger.slug(value);
}

/** Shared utility for rendering markdown */
export async function renderMarkdown(
content: string,
Expand Down
8 changes: 8 additions & 0 deletions packages/markdown/remark/src/ssr-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** Utilities used in deployment-ready SSR bundles */
import Slugger from 'github-slugger';

const slugger = new Slugger();
/** @see {@link "/packages/astro/vite-plugin-markdown"} */
export function slug(value: string): string {
return slugger.slug(value);
}