function getSourceUrl

Get portfolio source URL from request URL.

Examples

Basic WYSIWYG index

import { getRepoUrl, getSourceUrl } from './url_utils.ts'

const repoUrl = getRepoUrl('john.doe')
const index = getSourceUrl('/', repoUrl)
const file = getSourceUrl('/dir/path/file.any', repoUrl)

console.assert(index.href === new URL('./README.md', repoUrl).href)
console.assert(file.href === new URL('./dir/path/file.any', repoUrl).href)

Generated index

import { getRepoUrl, getSourceUrl } from './url_utils.ts'

const repoUrl = getRepoUrl('john.doe')
const baseUrl = new URL('./dist/', repoUrl)
const index = getSourceUrl('/', baseUrl)
const file = getSourceUrl('/dir/path/file.any', baseUrl)

console.assert(index.href === new URL('./dist/index.html', repoUrl).href)
console.assert(file.href === new URL('./dist/dir/path/file.any', repoUrl).href)

Parameters

filePath: string

request pathname of the file.

baseUrl: URL

Repository base url.

Return Type

URL of the source file.

Usage

import { getSourceUrl } from "url_utils.ts";