File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 1- // external_links_icon.ts adds an icon to external links in HTML pages
21import type { Page } from "../types/lume.ts" ;
3- export default function externalLinksIcon ( siteUrl : URL ) {
2+
3+ export default function externalLinksIcon ( siteUrl ?: URL ) {
4+ const fallbackUrl = new URL ( "https://blog.esolia.pro" ) ;
5+ const baseUrl = siteUrl instanceof URL ? siteUrl : fallbackUrl ;
6+
47 return ( pages : Page [ ] ) => {
58 for ( const page of pages ) {
69 const document = page . document ;
@@ -15,14 +18,13 @@ export default function externalLinksIcon(siteUrl: URL) {
1518 if ( ! href || href . startsWith ( "#" ) ) continue ;
1619
1720 try {
18- //const linkUrl = new URL(href, page.data.url || siteUrlStr);
19- const linkUrl = new URL ( href , siteUrl ) ;
21+ const linkUrl = new URL ( href , baseUrl ) ;
2022
2123 const isExternal =
2224 ( linkUrl . protocol === "http:" || linkUrl . protocol === "https:" ) &&
23- ( linkUrl . protocol !== siteUrl . protocol ||
24- linkUrl . hostname !== siteUrl . hostname ||
25- linkUrl . port !== siteUrl . port ) ;
25+ ( linkUrl . protocol !== baseUrl . protocol ||
26+ linkUrl . hostname !== baseUrl . hostname ||
27+ linkUrl . port !== baseUrl . port ) ;
2628
2729 if ( isExternal ) {
2830 link . classList . add ( "after:content-['_↗']" ) ;
You can’t perform that action at this time.
0 commit comments