config.js
1.0 kB · javascript · 38 lines
1const DEFAULTS = {2 title: '',3 since: new Date().getFullYear(),4 tint: null,5 menu: '/menu/',6 cart: '/cart/',7 company: '',8};910let current = { ...DEFAULTS };1112export function configure(site) {13 current = { ...DEFAULTS, ...site };14 return current;15}1617export function conf() {18 return current;19}2021/* BOOT */2223export function headScript(prefix = current.prefix || 'mrly-') {24 const body = `const d=document.documentElement;d.classList.add('js');try{for(const k of['theme','font','tint','saver']){const v=localStorage.getItem('${prefix}'+k);if(v)d.dataset[k]=v}}catch{}`;25 return `<script data-boot>(()=>{${body}})()</script>`;26}2728/* TINT */2930export const HUES = ['red', 'orange', 'yellow', 'green', 'mint', 'teal', 'cyan', 'blue', 'indigo', 'purple', 'pink', 'brown'];3132const rule = (hue, at) => `:root${at} { --accent: var(--${hue}); }`;3334export function tintCss(tint = current.tint) {35 const lines = HUES.includes(tint) ? [rule(tint, '')] : [];36 for (const hue of HUES) lines.push(rule(hue, `[data-tint="${hue}"]`));37 return `${lines.join('\n')}\n`;38}