0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

chore: refactor query param strip (#12714)

This commit is contained in:
Matt Kane 2024-12-11 11:06:55 +00:00 committed by GitHub
parent d33c2151a3
commit 99266fa289
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,7 +5,7 @@ import type { AstroSettings } from '../types/astro.js';
import type { AstroConfig } from '../types/public/config.js'; import type { AstroConfig } from '../types/public/config.js';
import type { RouteType } from '../types/public/internal.js'; import type { RouteType } from '../types/public/internal.js';
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js'; import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js';
import { removeTrailingForwardSlash, slash } from './path.js'; import { removeTrailingForwardSlash, slash, removeQueryString } from './path.js';
/** Returns true if argument is an object of any prototype/class (but not null). */ /** Returns true if argument is an object of any prototype/class (but not null). */
export function isObject(value: unknown): value is Record<string, any> { export function isObject(value: unknown): value is Record<string, any> {
@ -18,8 +18,7 @@ export function isURL(value: unknown): value is URL {
} }
/** Check if a file is a markdown file based on its extension */ /** Check if a file is a markdown file based on its extension */
export function isMarkdownFile(fileId: string, option?: { suffix?: string }): boolean { export function isMarkdownFile(fileId: string, option?: { suffix?: string }): boolean {
// Strip query string const id = removeQueryString(fileId);
const id = fileId.split('?')[0];
const _suffix = option?.suffix ?? ''; const _suffix = option?.suffix ?? '';
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) { for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
if (id.endsWith(`${markdownFileExtension}${_suffix}`)) return true; if (id.endsWith(`${markdownFileExtension}${_suffix}`)) return true;