feat: add configurable edit link next to revision
This commit is contained in:
committed by
Mathias Schopmans
parent
25a714e9f6
commit
b7efe8060f
@@ -1,6 +1,7 @@
|
||||
import config from "../../data/config.json";
|
||||
import data from "../../data/data.json";
|
||||
|
||||
import { format } from "@/lib/format";
|
||||
import { Flag, Item, Quadrant, Ring } from "@/lib/types";
|
||||
|
||||
export function getLabel(key: keyof typeof config.labels) {
|
||||
@@ -47,6 +48,11 @@ export function getTags(): string[] {
|
||||
return data.tags;
|
||||
}
|
||||
|
||||
export function getEditUrl(props: { id: string; release: string }) {
|
||||
if (!config.editUrl) return "";
|
||||
return format(config.editUrl, props);
|
||||
}
|
||||
|
||||
export function getQuadrants(): Quadrant[] {
|
||||
return config.quadrants.map((q, i) => ({ ...q, position: i + 1 }));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import { getAppName } from "@/lib/data";
|
||||
|
||||
// Replaces placeholders in a string with values from a context object
|
||||
// e.g. format("Hello {name}.", {name: "World"}) => "Hello World."
|
||||
export function format(text: string, context: Record<string, any>): string {
|
||||
return text.replace(/{(\w+)}/g, (match, key) => {
|
||||
return context[key] || match;
|
||||
});
|
||||
}
|
||||
|
||||
// Format the title of the page
|
||||
export function formatTitle(...title: string[]): string {
|
||||
return [...title, getAppName()].join(" | ");
|
||||
|
||||
Reference in New Issue
Block a user