core/assets/link.assets.ts
core/assets/link.assets.ts is a file in Bane's Lab Site. 99 lines of code and 52 definitions.
import { ANCHOR_PREFIX } from "#configuration/constants/document.constants";
import { HOME_PAGE } from "#core/ids/page.ids";
export const HOME_PATH = "/";
const QUERY_MARK = "?";
const pathOnly = function pathOnly(href: string): string {
const stops = [href.indexOf(QUERY_MARK), href.indexOf(ANCHOR_PREFIX)].filter((at) => at !== -1);
return stops.length === 0 ? href : href.slice(0, Math.min(...stops));
};
const segmentsOf = function segmentsOf(pathname: string): string[] {
return pathOnly(pathname)
.split(HOME_PATH)
.filter((segment) => segment.length > 0);
};
export const pagePath = function pagePath(page: string): string {
return page === HOME_PAGE ? HOME_PATH : HOME_PATH + page;
};
export const pageFromPath = function pageFromPath(pathname: string, home: string): string {
const [page] = segmentsOf(pathname);
return page ?? home;
};
export const tabFromPath = function tabFromPath(pathname: string): string | null {
const [, tab] = segmentsOf(pathname);
return tab ?? null;
};
export const tabLink = function tabLink(page: string, tab: string, section?: string): string {
const base = `${pagePath(page)}${HOME_PATH}${tab}`;
return section === undefined ? base : base + ANCHOR_PREFIX + section;
};
const NODE_SEGMENT = 2;
export const nodePath = function nodePath(page: string, tab: string, node: string): string {
return `${pagePath(page)}${HOME_PATH}${tab}${HOME_PATH}${node}`;
};
export const nodeFromPath = function nodeFromPath(pathname: string): string | null {
return segmentsOf(pathname).at(NODE_SEGMENT) ?? null;
};
export const RECORDS_SEGMENT = "records";
export const recordPath = function recordPath(collection: string, id: string): string {
return `${HOME_PATH}${RECORDS_SEGMENT}${HOME_PATH}${collection}${HOME_PATH}${id}`;
};
export const tabPath = function tabPath(page: string, tabs: readonly { readonly id: string }[], tab: string): string {
return tab === tabs[0]?.id ? pagePath(page) : tabLink(page, tab);
};
export const queryPath = function queryPath(page: string, parameter: string, value: string): string {
return pagePath(page) + QUERY_MARK + new URLSearchParams([[parameter, value]]).toString();
};
export const queryValue = function queryValue(search: string, parameter: string): string {
return new URLSearchParams(search).get(parameter) ?? "";
};
const JSON_ROUTE = "/json/";
export const payloadPath = function payloadPath(page: string, tab: string | null = null): string {
return tab === null ? JSON_ROUTE + page : JSON_ROUTE + page + HOME_PATH + tab;
};
const MARKDOWN_SUFFIX = ".md";
const HOME_TWIN = "/index";
export const markdownTwinPath = function markdownTwinPath(path: string): string {
return (path === HOME_PATH ? HOME_TWIN : path) + MARKDOWN_SUFFIX;
};
export const payloadTwinPath = function payloadTwinPath(path: string): string {
return payloadPath(pageFromPath(path, HOME_PAGE), tabFromPath(path));
};
const CATALOG_SEGMENT = "api";
const FACE_INDEX_SEGMENT = "/records/";
export const CATALOG_ROUTE = JSON_ROUTE + CATALOG_SEGMENT;
export const CATALOG_MARKDOWN_ROUTE = HOME_PATH + CATALOG_SEGMENT + MARKDOWN_SUFFIX;
export const faceIndexPath = function faceIndexPath(face: string): string {
return CATALOG_ROUTE + FACE_INDEX_SEGMENT + face;
};
const PAGE_INDEX_SEGMENT = "/pages/";
export const pageIndexPath = function pageIndexPath(page: string): string {
return CATALOG_ROUTE + PAGE_INDEX_SEGMENT + page;
};
export const sectionLeafPath = function sectionLeafPath(page: string, tab: string | null, section: string): string {
return payloadPath(page, tab) + HOME_PATH + section;
};
export const sectionMarkdownPath = function sectionMarkdownPath(
page: string,
tab: string | null,
section: string,
): string {
const base = tab === null ? pagePath(page) : tabLink(page, tab);
return base + HOME_PATH + section + MARKDOWN_SUFFIX;
};
export const LLMS_ROUTE = "/llms.txt";
export const FULL_TEXT_ROUTE = "/llms-full.txt";
export const SITE_URL = "https://banes-lab.com";
export const AUTHOR_ADDRESS = "jay@banes-lab.com";
export const AUTHOR_MAIL = `mailto:${AUTHOR_ADDRESS}`;
export const AUTHOR_PROFILE = "https://linkedin.com/in/jay-baleine";
export const AUTHOR_GITHUB = "https://github.com/Varietyz";
export const METHODOLOGY_REPOSITORY = "https://github.com/Varietyz/Disciplined-AI-Software-Development";
export const REPOSITORY_TREE = `${METHODOLOGY_REPOSITORY}/tree/main/`;
export const SOURCE_REPOSITORY_TREE = `${REPOSITORY_TREE}infrastructure`;
const LICENSE_ROOT = "/static/assets/";
export const LICENSE_FILE = `${LICENSE_ROOT}LICENSE`;
export const LICENSE_HEADER_FILE = `${LICENSE_ROOT}license.header.asset.txt`;
export const LICENSE_INQUIRY_MAIL = `${AUTHOR_MAIL}?subject=PAG Commercial License Inquiry`;
export const QUESTION_MAIL = `${AUTHOR_MAIL}?subject=Question about the methodology`;
export const GRAMMAR_REPOSITORY = "https://github.com/Varietyz/pag-lang";
export const CREATIVE_COMMONS = "https://creativecommons.org/licenses/by-sa/4.0/";