Changeset View
Changeset View
Standalone View
Standalone View
assets/src/utils/functions.js
Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | if (originUrlLower.match(ghUrlRegex)) { | ||||
} | } | ||||
// remove trailing slash | // remove trailing slash | ||||
if (originUrlLower.endsWith('/')) { | if (originUrlLower.endsWith('/')) { | ||||
originUrlLower = originUrlLower.slice(0, -1); | originUrlLower = originUrlLower.slice(0, -1); | ||||
} | } | ||||
// extract {owner}/{repo} | // extract {owner}/{repo} | ||||
const ownerRepo = originUrlLower.replace(ghUrlRegex, ''); | const ownerRepo = originUrlLower.replace(ghUrlRegex, ''); | ||||
// fetch canonical URL from github Web API | // fetch canonical URL from github Web API | ||||
const url = getCanonicalGithubOriginURL(ownerRepo); | const url = await getCanonicalGithubOriginURL(ownerRepo); | ||||
if (url) { | if (url) { | ||||
return url; | return url; | ||||
} | } | ||||
} | } | ||||
const ghpagesUrlRegex = /^http[s]*:\/\/(?<owner>[^/]+).github.io\/(?<repo>[^/]+)\/?.*/; | const ghpagesUrlRegex = /^http[s]*:\/\/(?<owner>[^/]+).github.io\/(?<repo>[^/]+)\/?.*/; | ||||
const parsedUrl = originUrlLower.match(ghpagesUrlRegex); | const parsedUrl = originUrlLower.match(ghpagesUrlRegex); | ||||
if (parsedUrl) { | if (parsedUrl) { | ||||
const ownerRepo = `${parsedUrl.groups.owner}/${parsedUrl.groups.repo}`; | const ownerRepo = `${parsedUrl.groups.owner}/${parsedUrl.groups.repo}`; | ||||
// fetch canonical URL from github Web API | // fetch canonical URL from github Web API | ||||
const url = getCanonicalGithubOriginURL(ownerRepo); | const url = await getCanonicalGithubOriginURL(ownerRepo); | ||||
if (url) { | if (url) { | ||||
return url; | return url; | ||||
} | } | ||||
} | } | ||||
return originUrl; | return originUrl; | ||||
} | } | ||||
export function getHumanReadableDate(data) { | export function getHumanReadableDate(data) { | ||||
// Display iso format date string into a human readable date | // Display iso format date string into a human readable date | ||||
// This is expected to be used by date field in datatable listing views | // This is expected to be used by date field in datatable listing views | ||||
// Example: 3/24/2022, 10:31:08 AM | // Example: 3/24/2022, 10:31:08 AM | ||||
const date = new Date(data); | const date = new Date(data); | ||||
return date.toLocaleString(); | return date.toLocaleString(); | ||||
} | } |