diff --git a/capytal/forgejo/assets/logo.png b/capytal/forgejo/assets/img/home-logo.png similarity index 100% rename from capytal/forgejo/assets/logo.png rename to capytal/forgejo/assets/img/home-logo.png diff --git a/capytal/forgejo/assets/logo.svg b/capytal/forgejo/assets/img/home-logo.svg similarity index 100% rename from capytal/forgejo/assets/logo.svg rename to capytal/forgejo/assets/img/home-logo.svg diff --git a/capytal/forgejo/assets/js/custom-theme.js b/capytal/forgejo/assets/js/custom-theme.js new file mode 100644 index 0000000..34b6b0b --- /dev/null +++ b/capytal/forgejo/assets/js/custom-theme.js @@ -0,0 +1,156 @@ +/** + * This is was a attempt to change the icons of the instance. The code works, + * but finding every single icon takes a lot of work, for little reward. + * + * For now this will be unused, until it is completed ~~some day~~. + */ + +/** + * SVG icons source code used below as strings are from the Solar Icon Set, + * by 480 Design, licensed under the Creative Commons' CC-BY 4.0 license. + * Source code were accessed via the Iconify API, via the icones.js.org front-end. + * + * Original set can be found here: + * https://www.figma.com/community/file/1166831539721848736/solar-icons-set + * + * Collection on icones.js.org can be found here: + * https://icones.js.org/collection/solar + */ + +// solar:bookmark-opened-bold-duotone +const REPO_ICON = ''; + +// solar:bookmark-opened-line-duotone +const REPO_TEMPLATE_ICON = ''; + +// solar:floor-lamp-broken +const REPO_FORK_ICON = ''; + +// solar:flip-horizontal-bold-duotone +const REPO_MIRROR_ICON = ''; + +// solar:lock-unlocked-bold-duotone +const LOCK_ICON = ''; + +// solar:buildings-bold-duotone +const ORG_ICON = ''; + +// solar:bookmark-circle-line-duotone +const COMMIT_ICON = ''; + +// solar:minus-circle-line-duotone +const ISSUE_OPENED_ICON = ''; + +// solar:bell-bold-duotone +const BELL_ICON = ''; + +// solar:hamburger-menu-broken +const MENU_ICON = ''; + +// solar:filter-bold-duotone +const MENU_FILTERS_ICON = ''; + +// solar:menu-dots-bold +const MENU_DOTS_ICON = ''; + +// solar:add-circle-bold-duotone +const PLUS_ICON = ''; + +// solar:alt-arrow-right-bold +const ARROW_RIGHT = ''; + +// solar:alt-arrow-left-bold +const ARROW_LEFT = ''; + +// solar:double-alt-arrow-right-bold-duotone +const DOUBLE_ARROW_RIGHT = ''; + +// solar:double-alt-arrow-right-left-duotone +const DOUBLE_ARROW_LEFT = ''; + +const VERSION = document.querySelector('.left-links > a[href="/admin/config"]')?.textContent || "0.0.0"; +if (VERSION === '0.0.0') { + console.warn('[Custom theme] Unable to find Forgejo version') +} + +const THEME_ELEM = + document.querySelector(`link[href="/assets/css/theme-capytal-dark-a.css?v=${VERSION}"]`) || + document.querySelector(`link[href="/assets/css/theme-capytal-light-a.css?v=${VERSION}"]`) +if (!THEME_ELEM) { + console.warn('[Custom theme] Capytal theme element not found') +} + +const IS_CAPYTAL_THEME = THEME_ELEM ? true : false; +if (IS_CAPYTAL_THEME) { + console.log('[Custom theme] Applying changes to Capytal theme') + main() +} else { + console.warn('[Custom theme] Not applying custom theme changes'); +} + +function main() { + applyChanges(); + + setTimeout(() => { + applyChanges(); + }, 500) + setTimeout(() => { + applyChanges(); + }, 1000) + setTimeout(() => { + applyChanges(); + }, 2000) +} + +function applyChanges() { + changeIcon('svg.svg.octicon-bell', BELL_ICON) + changeIcon('svg.svg.octicon-three-bars', MENU_ICON) + changeIcon('svg.svg.octicon-filter', MENU_FILTERS_ICON) + changeIcon('svg.svg.octicon-kebab-horizontal', MENU_DOTS_ICON) + changeIcon('svg.svg.octicon-plus', PLUS_ICON) + + changeIcon('svg.svg.octicon-chevron-right', ARROW_RIGHT) + changeIcon('svg.svg.octicon-chevron-left', ARROW_LEFT) + changeIcon('svg.svg.gitea-double-chevron-right', DOUBLE_ARROW_RIGHT) + changeIcon('svg.svg.gitea-double-chevron-left', DOUBLE_ARROW_LEFT) + + changeIcon('svg.svg.octicon-repo', REPO_ICON) + changeIcon('svg.svg.octicon-repo-push', REPO_ICON) + changeIcon('svg.svg.octicon-repo-template', REPO_TEMPLATE_ICON) + changeIcon('svg.svg.octicon-repo-forked', REPO_FORK_ICON) + changeIcon('svg.svg.octicon-mirror', REPO_MIRROR_ICON) + changeIcon('svg.svg.octicon-lock', LOCK_ICON) + + changeIcon('svg.svg.octicon-organization', ORG_ICON) + + changeIcon('svg.svg.octicon-git-commit', COMMIT_ICON) + changeIcon('svg.svg.octicon-issue-opened', ISSUE_OPENED_ICON) +} + +/** + * @param {string} html - The html to parse + * @returns {Element} - The resulting element + */ +function parseHTML(html) { + let el = document.createElement('div'); + el.innerHTML = html; + return el.children.item(0); +} + +/** + * @param {string} original - CSS selector of the original icon + * @param {string} newIcon - SVG text for the new icon + */ +function changeIcon(original, newIcon) { + let originalIcons = document.querySelectorAll(original); + for (const icon of originalIcons) { + let newEl = parseHTML(newIcon); + + newEl.setAttribute('width', icon.getAttribute('width') ?? "") + newEl.setAttribute('height', icon.getAttribute('height') ?? "") + newEl.setAttribute('class', icon.getAttribute('class') ?? "") + + icon.before(newEl) + icon.remove() + } +} diff --git a/capytal/forgejo/customization.nix b/capytal/forgejo/customization.nix index 5d09ccf..2f125d7 100644 --- a/capytal/forgejo/customization.nix +++ b/capytal/forgejo/customization.nix @@ -26,27 +26,12 @@ with builtins; let ''; in { services.forgejo.customization = { - assets = { - "fonts" = { - source = "${cal-sans}/fonts/webfonts"; - recursive = true; - }; - "fonts.css" = { - source = fonts-css; - }; - "img/home-logo.png" = { - source = ./assets/logo.png; - }; - "img/home-logo.svg" = { - source = ./assets/logo.svg; - }; - }; - templates = { - header = '' - - ${readFile ./templates/custom/header.tmpl} - ''; - home = ./templates/home.tmpl; + assets = ./assets; + templates = ./templates; + theme = { + "frappurccino" = frappurccino-theme; + "capytal-dark-b" = ./themes/theme-capytal-dark.css; + "bthree-dark" = ./themes/theme-bthree-dark.css; }; options.label."Default" = with config.scheme.withHashtag; { "scope/a11y" = { @@ -148,12 +133,5 @@ in { exclusive = true; }; }; - theme = { - "frappurccino" = frappurccino-theme; - }; - favicon.png = ./assets/icon.png; - favicon.svg = ./assets/icon.svg; - logo.png = ./assets/icon.png; - logo.svg = ./assets/icon.svg; }; } diff --git a/capytal/forgejo/templates/custom/_body_inner_pre.tmpl b/capytal/forgejo/templates/custom/_body_inner_pre.tmpl new file mode 100644 index 0000000..72a079c --- /dev/null +++ b/capytal/forgejo/templates/custom/_body_inner_pre.tmpl @@ -0,0 +1,731 @@ + + + + + + + diff --git a/capytal/forgejo/templates/custom/header.tmpl b/capytal/forgejo/templates/custom/header.tmpl index 645a4e0..6eca80f 100644 --- a/capytal/forgejo/templates/custom/header.tmpl +++ b/capytal/forgejo/templates/custom/header.tmpl @@ -1,7 +1,6 @@ - - +