Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Jul 27, 2023
1 parent 7dbcbc8 commit 9fe1089
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
6 changes: 4 additions & 2 deletions packages/astro/src/content/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
createComponent,
createHeadAndContent,
renderComponent,
renderUniqueScriptElement,
renderTemplate,
renderUniqueScriptElement,
renderUniqueStylesheet,
unescapeHTML,
type AstroComponentFactory,
Expand Down Expand Up @@ -303,7 +303,9 @@ async function render({
.join('');
}
if (Array.isArray(collectedScripts)) {
scripts = collectedScripts.map((script: any) => renderUniqueScriptElement(result, script)).join('');
scripts = collectedScripts
.map((script: any) => renderUniqueScriptElement(result, script))
.join('');
}

let props = baseProps;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export {
renderSlotToString,
renderTemplate,
renderToString,
renderUniqueStylesheet,
renderUniqueScriptElement,
renderUniqueStylesheet,
voidElementNames,
} from './render/index.js';
export type {
Expand Down
28 changes: 15 additions & 13 deletions packages/astro/src/runtime/server/render/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,44 @@ export function renderScriptElement({ props, children }: SSRElement) {
}

export function renderUniqueScriptElement(result: SSRResult, { props, children }: SSRElement) {
if(Array.from(result.scripts).some(s => {
if(s.props.type === props.type && s.props.src === props.src) {
return true;
}
if(!props.src && s.children === children) return true;
})) return '';
if (
Array.from(result.scripts).some((s) => {
if (s.props.type === props.type && s.props.src === props.src) {
return true;
}
if (!props.src && s.children === children) return true;
})
)
return '';
const key = `script-${props.type}-${props.src}-${children}`;
if(checkOrAddContentKey(result, key)) return '';
if (checkOrAddContentKey(result, key)) return '';
return renderScriptElement({ props, children });

}

export function renderUniqueStylesheet(result: SSRResult, sheet: StylesheetAsset) {
if (sheet.type === 'external') {
if (Array.from(result.styles).some((s) => s.props.href === sheet.src)) return '';
const key = 'link-external-' + sheet.src;
if(checkOrAddContentKey(result, key)) return '';
if (checkOrAddContentKey(result, key)) return '';
return renderElement('link', {
props: {
rel: 'stylesheet',
href: sheet.src
href: sheet.src,
},
children: ''
children: '',
});
}

if (sheet.type === 'inline') {
if (Array.from(result.styles).some((s) => s.children.includes(sheet.content))) return '';
const key = `link-inline-` + sheet.content;
if(checkOrAddContentKey(result, key)) return '';
if (checkOrAddContentKey(result, key)) return '';
return renderElement('style', { props: { type: 'text/css' }, children: sheet.content });
}
}

function checkOrAddContentKey(result: SSRResult, key: string): boolean {
if(result._metadata.contentKeys.has(key)) return true;
if (result._metadata.contentKeys.has(key)) return true;
result._metadata.contentKeys.add(key);
return false;
}

0 comments on commit 9fe1089

Please sign in to comment.