-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
32 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,11 @@ | ||
--- | ||
import { formatUrl } from '@/utils/validateUrl' | ||
import type { HTMLAttributes } from 'astro/types' | ||
type Props = Omit<HTMLAttributes<'a'>, 'slot'> | ||
const { class: className, href, ...attrs } = Astro.props | ||
const formattedHref = href && formatUrl(href) | ||
--- | ||
|
||
<a | ||
href={formattedHref} | ||
class:list={['text-blue-600 underline', className]} | ||
{...attrs} | ||
> | ||
<a href={href} class:list={['text-blue-600 underline', className]} {...attrs}> | ||
<slot /> | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,21 @@ | ||
/** 対象のURL */ | ||
const pattern = new RegExp( | ||
`^(${import.meta.env.SITE.replaceAll('.', '\\.')}|/)`, | ||
) | ||
|
||
/** | ||
* oucc.orgに向けたURLの末尾に/をつけます | ||
*/ | ||
export function formatUrl(path: string | URL): string { | ||
if (path instanceof URL) return formatUrl(path.href) | ||
|
||
if (!path.match(pattern)) return path | ||
|
||
const [url, hash] = path.split('#') | ||
export function getFormatUrl(base: string = import.meta.env.SITE) { | ||
/** 対象のURL */ | ||
const pattern = new RegExp(`^(${base.replaceAll('.', '\\.')}|/)`) | ||
|
||
if (url!.endsWith('/')) return path | ||
return hash ? `${url}/#${hash}` : url + '/' | ||
} | ||
return function formatUrl(path: string | URL): string { | ||
if (path instanceof URL) return formatUrl(path.href) | ||
|
||
/** | ||
* oucc.orgに向けたURLの末尾に/がない場合、例外を発生させます | ||
* @throws {Error} - URLが条件を満たさない場合に発生する例外 | ||
*/ | ||
export function validateUrl(path: string): void { | ||
if (!path.match(pattern)) return | ||
if (!path.match(pattern)) return path | ||
|
||
const [url] = path.split('#') | ||
const [url, hash] = path.split('#') | ||
|
||
if (url!.endsWith('/')) return | ||
if (url!.endsWith('/')) return path | ||
// ファイル拡張子 | ||
if (url!.match(/\.(a-zA-Z0-9)+$/)) return path | ||
|
||
throw new Error(`URLの末尾には/が必要です。 url:${url}`) | ||
return hash ? `${url}/#${hash}` : url + '/' | ||
} | ||
} |