fix too strict "relative link" errors in docs website (#1149)
This commit is contained in:
parent
d18402de3a
commit
c4e9ce3b14
2 changed files with 6 additions and 4 deletions
|
@ -22,7 +22,7 @@ import { transform } from '../transform/index.js';
|
|||
import { PRISM_IMPORT } from '../transform/prism.js';
|
||||
import { nodeBuiltinsSet } from '../../node_builtins.js';
|
||||
import { readFileSync } from 'fs';
|
||||
import { pathToFileURL } from 'url';
|
||||
import { fileURLToPath, pathToFileURL } from 'url';
|
||||
|
||||
const { parse, FEATURE_CUSTOM_ELEMENT } = astroParser;
|
||||
const traverse: typeof babelTraverse.default = (babelTraverse.default as any).default;
|
||||
|
@ -61,6 +61,7 @@ function findHydrationAttributes(attrs: Record<string, string>): HydrationAttrib
|
|||
|
||||
/** Retrieve attributes from TemplateNode */
|
||||
async function getAttributes(nodeName: string, attrs: Attribute[], state: CodegenState, compileOptions: CompileOptions): Promise<Record<string, string>> {
|
||||
const isPage = state.filename.startsWith(fileURLToPath(compileOptions.astroConfig.pages));
|
||||
let result: Record<string, string> = {};
|
||||
for (const attr of attrs) {
|
||||
if (attr.type === 'Spread') {
|
||||
|
@ -112,8 +113,9 @@ async function getAttributes(nodeName: string, attrs: Attribute[], state: Codege
|
|||
}
|
||||
case 'Text': {
|
||||
let text = getTextFromAttribute(val);
|
||||
|
||||
if (!isPage) {
|
||||
warnIfRelativeStringLiteral(compileOptions.logging, nodeName, attr, text);
|
||||
}
|
||||
result[attr.name] = JSON.stringify(text);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ export function isImportMetaDeclaration(declaration: VariableDeclarator, metaNam
|
|||
|
||||
const warnableRelativeValues = new Set(['img+src', 'a+href', 'script+src', 'link+href', 'source+srcset']);
|
||||
|
||||
const matchesRelative = /^(?![A-Za-z][+-.0-9A-Za-z]*:|\/)/;
|
||||
const matchesRelative = /^(?![A-Za-z][+-.0-9A-Za-z]*:|\/|#)/;
|
||||
|
||||
export function warnIfRelativeStringLiteral(logging: LogOptions, nodeName: string, attr: Attribute, value: string) {
|
||||
let key = nodeName + '+' + attr.name;
|
||||
|
|
Loading…
Reference in a new issue