2022-05-22 15:13:30 +03:00
|
|
|
import { AnyNode, Attrs, E, Elem } from "ren/node.ts";
|
|
|
|
import { classNames } from "ren/attrs.ts";
|
|
|
|
import { Context } from "../context.ts";
|
|
|
|
|
|
|
|
export function PageLayout(ctx: Context, children: AnyNode[]): Elem {
|
|
|
|
return E("div", { id: "main" }, [
|
|
|
|
Header(ctx),
|
|
|
|
E("div", classNames("content"), children),
|
2022-05-27 23:07:07 +03:00
|
|
|
Footer(),
|
2022-05-22 15:13:30 +03:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-05-27 23:07:07 +03:00
|
|
|
export function Header(ctx: Context): AnyNode {
|
2022-05-22 15:13:30 +03:00
|
|
|
return E("header", classNames("header"), [
|
|
|
|
E("div", classNames("content-width"), [HeaderNav(ctx)]),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-05-27 23:07:07 +03:00
|
|
|
export function HeaderNav(ctx: Context): AnyNode {
|
2022-05-22 15:13:30 +03:00
|
|
|
return E("nav", classNames("main-menu"), [
|
2022-05-27 23:07:07 +03:00
|
|
|
Link("Главная", navLink("/", ctx)),
|
|
|
|
Link("Рецепты", navLink("/recipes", ctx)),
|
|
|
|
Link("Ингредиенты", navLink("/ingredients", ctx)),
|
2022-05-22 15:13:30 +03:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function navLink(href: string, ctx?: Context): Attrs {
|
|
|
|
const attrs: Attrs = { href };
|
|
|
|
if (ctx?.locPath === href) attrs["aria-current"] = "true";
|
|
|
|
return attrs;
|
|
|
|
}
|
|
|
|
|
2022-05-27 23:07:07 +03:00
|
|
|
export function Footer(): AnyNode {
|
|
|
|
return E("footer", classNames("footer"), [
|
|
|
|
E("div", classNames("content-width"), [
|
|
|
|
Link("Исходный код", {
|
|
|
|
href: "https://notabug.org/pleshevskiy/recipes",
|
|
|
|
rel: "external nofollow noopener noreferrer",
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function Link(text: string, attrs: Attrs | Attrs[]): AnyNode {
|
|
|
|
return E("a", attrs, text);
|
2022-05-22 15:13:30 +03:00
|
|
|
}
|