Skip to content

Commit

Permalink
fix too strict "relative link" errors in docs website (withastro#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Aug 18, 2021
1 parent d18402d commit c4e9ce3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/astro/src/compiler/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -112,8 +113,9 @@ async function getAttributes(nodeName: string, attrs: Attribute[], state: Codege
}
case 'Text': {
let text = getTextFromAttribute(val);

warnIfRelativeStringLiteral(compileOptions.logging, nodeName, attr, text);
if (!isPage) {
warnIfRelativeStringLiteral(compileOptions.logging, nodeName, attr, text);
}
result[attr.name] = JSON.stringify(text);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/compiler/codegen/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c4e9ce3

Please sign in to comment.