mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
refactor(astro): code refactor (#11343)
This commit is contained in:
parent
10ba3d4d6a
commit
1bf863e5c9
7 changed files with 26 additions and 26 deletions
|
@ -215,14 +215,15 @@ async function ssrBuild(
|
||||||
if (isContentCache) {
|
if (isContentCache) {
|
||||||
prefix += `${buildID}/`;
|
prefix += `${buildID}/`;
|
||||||
suffix = '.mjs';
|
suffix = '.mjs';
|
||||||
}
|
|
||||||
|
|
||||||
if (isContentCache && name.includes('/content/')) {
|
if (name.includes('/content/')) {
|
||||||
const parts = name.split('/');
|
const parts = name.split('/');
|
||||||
if (parts.at(1) === 'content') {
|
if (parts.at(1) === 'content') {
|
||||||
return encodeName(parts.slice(1).join('/'));
|
return encodeName(parts.slice(1).join('/'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sometimes chunks have the `@_@astro` suffix due to SSR logic. Remove it!
|
// Sometimes chunks have the `@_@astro` suffix due to SSR logic. Remove it!
|
||||||
// TODO: refactor our build logic to avoid this
|
// TODO: refactor our build logic to avoid this
|
||||||
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
|
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
|
||||||
|
|
|
@ -146,8 +146,7 @@ export async function getViteErrorPayload(err: ErrorWithMetadata): Promise<Astro
|
||||||
let highlighterLang = err.loc?.file?.split('.').pop();
|
let highlighterLang = err.loc?.file?.split('.').pop();
|
||||||
if (ALTERNATIVE_JS_EXTS.includes(highlighterLang ?? '')) {
|
if (ALTERNATIVE_JS_EXTS.includes(highlighterLang ?? '')) {
|
||||||
highlighterLang = 'js';
|
highlighterLang = 'js';
|
||||||
}
|
} else if (ALTERNATIVE_MD_EXTS.includes(highlighterLang ?? '')) {
|
||||||
if (ALTERNATIVE_MD_EXTS.includes(highlighterLang ?? '')) {
|
|
||||||
highlighterLang = 'md';
|
highlighterLang = 'md';
|
||||||
}
|
}
|
||||||
const highlightedCode = err.fullCode
|
const highlightedCode = err.fullCode
|
||||||
|
|
|
@ -695,6 +695,10 @@ class ErrorOverlay extends HTMLElement {
|
||||||
|
|
||||||
const el = this.root.querySelector(selector);
|
const el = this.root.querySelector(selector);
|
||||||
|
|
||||||
|
if (!el) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (html) {
|
if (html) {
|
||||||
// Automatically detect links
|
// Automatically detect links
|
||||||
text = text
|
text = text
|
||||||
|
@ -706,14 +710,10 @@ class ErrorOverlay extends HTMLElement {
|
||||||
return `<a target="_blank" href="${v}">${v}</a>`;
|
return `<a target="_blank" href="${v}">${v}</a>`;
|
||||||
})
|
})
|
||||||
.join(' ');
|
.join(' ');
|
||||||
}
|
|
||||||
|
|
||||||
if (el) {
|
el.innerHTML = text.trim();
|
||||||
if (!html) {
|
} else {
|
||||||
el.textContent = text.trim();
|
el.textContent = text.trim();
|
||||||
} else {
|
|
||||||
el.innerHTML = text.trim();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,15 +56,16 @@ export async function callMiddleware(
|
||||||
let responseFunctionPromise: Promise<Response> | Response | undefined = undefined;
|
let responseFunctionPromise: Promise<Response> | Response | undefined = undefined;
|
||||||
const next: MiddlewareNext = async (payload) => {
|
const next: MiddlewareNext = async (payload) => {
|
||||||
nextCalled = true;
|
nextCalled = true;
|
||||||
if (!enableRerouting && payload) {
|
|
||||||
logger.warn(
|
|
||||||
'router',
|
|
||||||
'The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (enableRerouting) {
|
if (enableRerouting) {
|
||||||
responseFunctionPromise = responseFunction(apiContext, payload);
|
responseFunctionPromise = responseFunction(apiContext, payload);
|
||||||
} else {
|
} else {
|
||||||
|
if (payload) {
|
||||||
|
logger.warn(
|
||||||
|
'router',
|
||||||
|
'The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.'
|
||||||
|
);
|
||||||
|
}
|
||||||
responseFunctionPromise = responseFunction(apiContext);
|
responseFunctionPromise = responseFunction(apiContext);
|
||||||
}
|
}
|
||||||
// We need to pass the APIContext pass to `callMiddleware` because it can be mutated across middleware functions
|
// We need to pass the APIContext pass to `callMiddleware` because it can be mutated across middleware functions
|
||||||
|
|
|
@ -25,8 +25,7 @@ function redirectRouteGenerate(renderContext: RenderContext): string {
|
||||||
let target = redirect;
|
let target = redirect;
|
||||||
for (const param of Object.keys(params)) {
|
for (const param of Object.keys(params)) {
|
||||||
const paramValue = params[param]!;
|
const paramValue = params[param]!;
|
||||||
target = target.replace(`[${param}]`, paramValue);
|
target = target.replace(`[${param}]`, paramValue).replace(`[...${param}]`, paramValue);
|
||||||
target = target.replace(`[...${param}]`, paramValue);
|
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
} else if (typeof redirect === 'undefined') {
|
} else if (typeof redirect === 'undefined') {
|
||||||
|
|
|
@ -29,8 +29,7 @@ export function transformSlots(vnode: AstroVNode) {
|
||||||
slots[name]['$$slot'] = true;
|
slots[name]['$$slot'] = true;
|
||||||
delete child.props.slot;
|
delete child.props.slot;
|
||||||
delete vnode.props.children;
|
delete vnode.props.children;
|
||||||
}
|
} else if (Array.isArray(vnode.props.children)) {
|
||||||
if (Array.isArray(vnode.props.children)) {
|
|
||||||
// Handle many children with slot attributes
|
// Handle many children with slot attributes
|
||||||
vnode.props.children = vnode.props.children
|
vnode.props.children = vnode.props.children
|
||||||
.map((child) => {
|
.map((child) => {
|
||||||
|
|
|
@ -92,8 +92,9 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
if (!(evt instanceof CustomEvent)) return;
|
if (!(evt instanceof CustomEvent)) return;
|
||||||
|
|
||||||
const target = overlay.shadowRoot?.querySelector(`[data-app-id="${app.id}"]`);
|
const target = overlay.shadowRoot?.querySelector(`[data-app-id="${app.id}"]`);
|
||||||
const notificationElement = target?.querySelector('.notification');
|
if (!target) return;
|
||||||
if (!target || !notificationElement) return;
|
const notificationElement = target.querySelector('.notification');
|
||||||
|
if (!notificationElement) return;
|
||||||
|
|
||||||
let newState = evt.detail.state ?? true;
|
let newState = evt.detail.state ?? true;
|
||||||
let level = notificationLevels.includes(evt?.detail?.level)
|
let level = notificationLevels.includes(evt?.detail?.level)
|
||||||
|
|
Loading…
Add table
Reference in a new issue