Updated kodukord and lol rules in est

This commit is contained in:
2026-05-14 20:55:34 +03:00
parent 206d098360
commit 08431e22d6
7 changed files with 236 additions and 94 deletions

View File

@@ -109,7 +109,7 @@ const Header = ({ navItems }: HeaderProps) => {
aria-current={isActive ? "page" : undefined}
aria-disabled={isActive ? true : undefined}
tabIndex={isActive ? -1 : undefined}
className={`${vipnagorgialla.className} group font-bold italic leading-none text-lg uppercase px-4 py-1.5 border-4 border-[#00A3E0] transition ${
className={`${vipnagorgialla.className} group font-bold italic leading-none text-lg uppercase px-4 py-2 border-4 border-[#00A3E0] transition ${
isActive
? "bg-[#00A3E0] text-black cursor-default pointer-events-none"
: "bg-[#1F5673] text-[#EEE5E5] hover:bg-[#00A3E0] hover:text-black"

View File

@@ -0,0 +1,90 @@
import { getTranslations } from "next-intl/server";
import type { Locale, RuleType } from "@/lib/loadRules";
type GithubCommit = {
commit?: {
committer?: {
date?: string;
};
};
};
type RulesLastChangedProps = {
locale: Locale;
ruleType: RuleType;
className?: string;
};
const apiBaseUrl = "https://api.github.com/repos/Lapikud/tipilan/commits";
function buildCommitUrl(ruleType: RuleType, locale: Locale): string {
return `${apiBaseUrl}?path=src/data/rules/${locale}/${ruleType}.md&page=1&per_page=1`;
}
async function fetchCommitDate(url: string): Promise<string | null> {
try {
const response = await fetch(url, {
headers: {
Accept: "application/vnd.github+json",
},
next: { revalidate: 3600 },
});
if (!response.ok) {
console.warn(
`Failed to fetch last changed date: ${response.status} ${response.statusText}`,
);
return null;
}
const data = (await response.json()) as GithubCommit[];
return data?.[0]?.commit?.committer?.date ?? null;
} catch (error) {
console.warn("Failed to fetch last changed date", error);
return null;
}
}
async function getLastChangedDate(
ruleType: RuleType,
locale: Locale,
): Promise<string | null> {
const primary = await fetchCommitDate(buildCommitUrl(ruleType, locale));
if (primary) {
return primary;
}
if (locale !== "et") {
return fetchCommitDate(buildCommitUrl(ruleType, "et"));
}
return null;
}
export default async function RulesLastChanged({
locale,
ruleType,
className,
}: RulesLastChangedProps) {
const t = await getTranslations({ locale });
const lastChangedIso = await getLastChangedDate(ruleType, locale);
if (!lastChangedIso) {
return null;
}
const lastChangedDate = new Intl.DateTimeFormat(
locale === "et" ? "et-EE" : "en-US",
{
dateStyle: "long",
},
).format(new Date(lastChangedIso));
const classes = `text-white mb-6 leading-[19px]${className ? ` ${className}` : ""}`;
return (
<p className={classes}>
{t("rules.lastChanged")} {lastChangedDate}
</p>
);
}