mirror of
https://github.com/withastro/astro.git
synced 2025-01-22 10:31:53 -05:00
fix: allow imports of Markdown files as raw text (#13026)
* fix: allow imports of Markdown files as raw text * Switch to hasSpecialQueries * Update test * Update changeset
This commit is contained in:
parent
0a0b1978a7
commit
1d272f6a5a
4 changed files with 22 additions and 1 deletions
5
.changeset/large-dodos-bake.md
Normal file
5
.changeset/large-dodos-bake.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes a regression that prevented the import of Markdown files as raw text or URLs.
|
|
@ -6,6 +6,7 @@ import type { AstroConfig } from '../types/public/config.js';
|
|||
import type { RouteData } from '../types/public/internal.js';
|
||||
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js';
|
||||
import { removeQueryString, removeTrailingForwardSlash, slash } from './path.js';
|
||||
import { hasSpecialQueries } from '../vite-plugin-utils/index.js';
|
||||
|
||||
/** Returns true if argument is an object of any prototype/class (but not null). */
|
||||
export function isObject(value: unknown): value is Record<string, any> {
|
||||
|
@ -18,6 +19,9 @@ export function isURL(value: unknown): value is URL {
|
|||
}
|
||||
/** Check if a file is a markdown file based on its extension */
|
||||
export function isMarkdownFile(fileId: string, option?: { suffix?: string }): boolean {
|
||||
if (hasSpecialQueries(fileId)) {
|
||||
return false;
|
||||
}
|
||||
const id = removeQueryString(fileId);
|
||||
const _suffix = option?.suffix ?? '';
|
||||
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
|
||||
|
|
|
@ -24,6 +24,15 @@ describe('Astro Markdown', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('Allows ?raw and ?url imports', async () => {
|
||||
const { rawImport, url } = JSON.parse(await fixture.readFile('/raw-content.json'));
|
||||
assert.equal(
|
||||
fixLineEndings(rawImport).trim(),
|
||||
`# Basic page\n\nLets make sure raw and compiled content look right!`,
|
||||
);
|
||||
assert.ok(url.startsWith("data:text/markdown;base64,"));
|
||||
});
|
||||
|
||||
it('Exposes compiled HTML content', async () => {
|
||||
const { compiled } = JSON.parse(await fixture.readFile('/raw-content.json'));
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import { compiledContent, rawContent } from './basic.md';
|
||||
|
||||
import md from './basic.md?raw';
|
||||
import url from './basic.md?url';
|
||||
export async function GET() {
|
||||
return Response.json({
|
||||
raw: rawContent(),
|
||||
compiled: await compiledContent(),
|
||||
rawImport: md,
|
||||
url,
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue