Files
LithosAnanke/site/colorlock.py
T
Claude 038556bb3e
Build / Image MILKV (push) Canceled after 0s
Build / Image PC (push) Canceled after 0s
Build / Image RASPI (push) Canceled after 0s
Build / v4 tests (32- and 64-bit cells) (push) Canceled after 0s
site: visitors see the design alone, not XWiki's chrome
Captain Bob, 2026-11-07: "Menu bar". For guests only, the .com pages and
the .org landing page hide XWiki's top bar, breadcrumb, title block, page
menu, panels, footer and tour, and the design runs the full width (a
velocity check on $isGuest; the stylesheet in a literal block). Logged in,
the wiki is all there. Checked on a phone and a desktop: the chrome is
hidden on Main, Inquiries and TryIt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GE3SDvQn5EoxdGufk84zz2
2026-11-07 13:51:15 +00:00

65 lines
3.4 KiB
Python

"""colorlock.py -- keep a page's own colours inside a wiki whose theme forces its own.
Both XWikis carry a high-contrast theme (skins/flamingo/cssVariablesInit.css on the server) that sets
every element black on white with !important. On our pages the design's colours win instead
(Captain Bob, 2026-11-07), and on those pages only; the rest of the wiki keeps the theme:
- every colour an element states in its style="" is made !important -- an inline !important beats
any stylesheet's;
- a stylesheet scoped to the page's root (class "ssos") covers the elements that state no colour:
".ssos *" outranks the theme's "*" (both !important, the more specific wins).
"""
import re
ROOT_CLASS = "ssos"
STYLE = """<style>
.ssos, .ssos *, .ssos *::before, .ssos *::after { background-color: transparent !important; color: inherit !important; border-color: #22324D !important; }
.ssos a, .ssos a * { color: #F5891F !important; }
.ssos a:hover { color: #FFB061 !important; }
.ssos input, .ssos textarea, .ssos select { background-color: #0A1222 !important; color: #EEF2F7 !important; border-color: #34486A !important; }
.ssos ::placeholder { color: #A3AEC2 !important; opacity: 1 !important; }
.ssos img { background-color: transparent !important; }
</style>"""
COLOUR_PROPS = re.compile(r"^\s*(color|background|background-color|border|border-(top|right|bottom|left)|"
r"border-color|border-(top|right|bottom|left)-color|accent-color|fill)\s*:", re.I)
def _lock_style(m):
decls = []
for d in m.group(1).split(";"):
if d.strip() and COLOUR_PROPS.match(d) and "!important" not in d:
d = d.rstrip() + " !important"
decls.append(d)
return 'style="%s"' % ";".join(decls)
def lock(html, root_marker):
"""root_marker: the opening text of the page's root element, e.g. '<div style="background: #0A1222'."""
assert html.count(root_marker) >= 1, root_marker
html = html.replace(root_marker, root_marker.replace("<div ", '<div class="%s" ' % ROOT_CLASS, 1), 1)
html = re.sub(r'style="([^"]*)"', _lock_style, html)
return STYLE + "\n" + html
# For visitors (guests) only, the page is the design alone: XWiki's own chrome -- the top bar with
# Register and Log-in, the breadcrumb, the title and "Last modified", the page menu, the side panels,
# the footer and the welcome tour -- is hidden, and the design runs the full width. Logged in, the
# wiki is all there, to edit with. (Captain Bob, 2026-11-07: "Menu bar".)
GUEST_CHROME = """{{velocity}}
#if ($isGuest)
#[[{{html clean="false"}}<style>
#menuview, #hierarchy_breadcrumb, .document-header, #xdocFooter, #footerglobal, #leftPanels, #rightPanels,
#leftPanelsToggle, #rightPanelsToggle, .tour, .tour-backdrop, #bootstrap_tour_restart, .xtour-restart,
#xwikimaincontainerinner > a.btn { display: none !important; }
html, body, #xwikimaincontainer, #xwikimaincontainerinner, #contentcontainer, #contentcolumn, .main,
#mainContentArea, #xwikicontent, #mainContentArea .row { background-color: #0A1222 !important; }
#contentcontainer, #contentcolumn, .main, #mainContentArea, #xwikicontent, #mainContentArea .row {
width: 100% !important; max-width: none !important; margin: 0 !important; padding: 0 !important; border: 0 !important; float: none !important; }
#xwikicontent > .ssos { border: 0 !important; }
#xwikimaincontainer { padding: 0 !important; }
.main hr:not(.ssos hr), #xwikicontent > :not(.ssos) { display: none !important; }
</style>{{/html}}]]#
#end
{{/velocity}}
"""