Skip to content

Commit

Permalink
allow building of additional color themes (and use them to visualize …
Browse files Browse the repository at this point in the history
…decryption of encryptcontent plugin)
  • Loading branch information
unverbuggt committed Aug 31, 2023
1 parent 7e30bbd commit e619726
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 32 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ plugins:
- color-theme: # optional
theme_color: '#ff6600' # primary color
secondary_color: 'complementary' # can be a color or scheme
#extra_css_light: # list of extra CSS for light mode
# - 'css/additional-light.css'
#extra_css_dark: # list of extra CSS for dark mode
# - 'css/additional-dark.css'
light_text_color: '#000' # black
dark_text_color: '#fff' # white
extra_css_light: # list of extra CSS for light mode
- 'css/additional-light.css'
extra_css_dark: # list of extra CSS for dark mode
- 'css/additional-dark.css'
additional: # build these themes also
- theme_color: '#44bb4f'
secondary_color: 'complementary'

- w3css-classes: {} # mandatory

Expand Down
19 changes: 11 additions & 8 deletions docs/de/colors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ Durch die Option `extra_css_light` und `extra_css_dark` können zusätzliche CSS
plugins:
#...
- color-theme:
theme_color: '#ef6110' #Hauptfarbe
secondary_color: 'complementary' #Zweitfarbe oder Farbschema
light_text_color: '#000' #Schwarz
dark_text_color: '#fff' #Weiss
#extra_css_light: #Liste mit zuätzlichen CSS Dateien für die helle Ansicht
# - 'css/additional-light.css'
#extra_css_dark: #Liste mit zuätzlichen CSS Dateien für die dunkle Ansicht
# - 'css/additional-dark.css'
theme_color: '#ef6110' # Hauptfarbe
secondary_color: 'complementary' # Zweitfarbe oder Farbschema
light_text_color: '#000' # Schwarz
dark_text_color: '#fff' # Weiss
extra_css_light: # Liste mit zusätzlichen CSS Dateien für die helle Ansicht
- 'css/additional-light.css'
extra_css_dark: # Liste mit zusätzlichen CSS Dateien für die dunkle Ansicht
- 'css/additional-dark.css'
additional: # Diese themes auch noch erzeugen
- theme_color: '#44bb4f'
secondary_color: 'complementary'
#...
```

Expand Down
9 changes: 8 additions & 1 deletion docs/de/extensions/encryptcontent.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ Um eine Seite zu verschlüsseln muss nur der Wert `password` gesetzt werden.

```markdown
password: 12345
```
```

<script id="autostart">
const ctheme = 'css/w3-theme-44bb4f-complementary';
document.getElementById('theme-auto').href = base_url + '/' + ctheme + '.css';
document.getElementById('theme-light').href = base_url + '/' + ctheme + '-light.css';
document.getElementById('theme-dark').href = base_url + '/' + ctheme + '-dark.css';
</script>
19 changes: 11 additions & 8 deletions docs/en/colors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ Use options `extra_css_light` and `extra_css_dark` to integrate additional CSS t
plugins:
#...
- color-theme:
theme_color: '#ef6110' #primary color
secondary_color: 'complementary' #can be a color or scheme
light_text_color: '#000' #black
dark_text_color: '#fff' #white
#extra_css_light: #list of extra CSS for light mode
# - 'css/additional-light.css'
#extra_css_dark: #list of extra CSS for dark mode
# - 'css/additional-dark.css'
theme_color: '#ef6110' # primary color
secondary_color: 'complementary' # can be a color or scheme
light_text_color: '#000' # black
dark_text_color: '#fff' # white
extra_css_light: # list of extra CSS for light mode
- 'css/additional-light.css'
extra_css_dark: # list of extra CSS for dark mode
- 'css/additional-dark.css'
additional: # build these themes also
- theme_color: '#44bb4f'
secondary_color: 'complementary'
#...
```

Expand Down
9 changes: 8 additions & 1 deletion docs/en/extensions/encryptcontent.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ Pages can be marked for encryption by adding the meta `password`.

```markdown
password: 12345
```
```

<script id="autostart">
const ctheme = 'css/w3-theme-44bb4f-complementary';
document.getElementById('theme-auto').href = base_url + '/' + ctheme + '.css';
document.getElementById('theme-light').href = base_url + '/' + ctheme + '-light.css';
document.getElementById('theme-dark').href = base_url + '/' + ctheme + '-dark.css';
</script>
4 changes: 4 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ plugins:
extra_css_dark:
- 'extra_css/stackoverflow-dark.min.css'
- 'extra_css/tablesort-dark.css'
additional:
- theme_color: '#44bb4f'
secondary_color: 'complementary'

- w3css-classes: {}

Expand Down Expand Up @@ -128,6 +131,7 @@ plugins:
selfhost_dir: 'theme_override'
reload_scripts:
- '#theme'
- '#autostart'
translations:
en:
title_prefix: ''
Expand Down
4 changes: 4 additions & 0 deletions mkdocs_gh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ plugins:
extra_css_dark:
- 'extra_css/stackoverflow-dark.min.css'
- 'extra_css/tablesort-dark.css'
additional:
- theme_color: '#44bb4f'
secondary_color: 'complementary'

- w3css-classes: {}

Expand Down Expand Up @@ -129,6 +132,7 @@ plugins:
selfhost_dir: 'theme_override'
reload_scripts:
- '#theme'
- '#autostart'
translations:
de:
title_prefix: ''
Expand Down
20 changes: 10 additions & 10 deletions risonia_theme/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
{%- block styles %}
<link rel="stylesheet" href="{{ 'css/w3.css'|url }}">
{%- if page_theme %}
<link rel="stylesheet" href="{{ ('css/w3-theme-'+page_theme+'.css')|url }}">
<link rel="stylesheet" href="{{ ('css/w3-theme-'+page_theme+'-light.css')|url }}" media="none" id="light">
<link rel="stylesheet" href="{{ ('css/w3-theme-'+page_theme+'-dark.css')|url }}" media="none" id="dark">
<link rel="stylesheet" href="{{ ('css/w3-theme-'+page_theme+'.css')|url }}" id="theme-auto">
<link rel="stylesheet" href="{{ ('css/w3-theme-'+page_theme+'-light.css')|url }}" media="none" id="theme-light">
<link rel="stylesheet" href="{{ ('css/w3-theme-'+page_theme+'-dark.css')|url }}" media="none" id="theme-dark">
{%- else %}
<link rel="stylesheet" href="{{ 'css/w3-theme.css'|url }}">
<link rel="stylesheet" href="{{ 'css/w3-theme-light.css'|url }}" media="none" id="light">
<link rel="stylesheet" href="{{ 'css/w3-theme-dark.css'|url }}" media="none" id="dark">
<link rel="stylesheet" href="{{ 'css/w3-theme.css'|url }}" id="theme-auto">
<link rel="stylesheet" href="{{ 'css/w3-theme-light.css'|url }}" media="none" id="theme-light">
<link rel="stylesheet" href="{{ 'css/w3-theme-dark.css'|url }}" media="none" id="theme-dark">
{%- endif %}
<link rel="stylesheet" href="{{ 'css/theme.css'|url }}">
{%- for path in config.extra_css %}
Expand All @@ -75,12 +75,12 @@
let theme = localStorage.getItem(themeItem);
if (theme) {
if (theme == 'light') {
document.getElementById('dark').media = 'none';
document.getElementById('light').media = '';
document.getElementById('theme-dark').media = 'none';
document.getElementById('theme-light').media = '';
}
if (theme == 'dark') {
document.getElementById('light').media = 'none';
document.getElementById('dark').media = '';
document.getElementById('theme-light').media = 'none';
document.getElementById('theme-dark').media = '';
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions risonia_theme/plugins/color/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from colorsys import rgb_to_hls
from colorsys import hls_to_rgb
import math
import logging

from jinja2 import Template

Expand All @@ -16,6 +17,8 @@
except ImportError:
string_types = str

logger = logging.getLogger("mkdocs.plugins.colortheme")

#PLUGIN_DIR = os.path.dirname(os.path.realpath(__file__))
#CSS_TPL_PATH = os.path.join(PLUGIN_DIR, 'w3-theme.jinja2.py')

Expand Down Expand Up @@ -113,6 +116,7 @@ class W3cssColorTheme(BasePlugin):
('dark_text_color', config_options.Type(str, default='#fff')),
('extra_css_light', config_options.Type(list, default=[])),
('extra_css_dark', config_options.Type(list, default=[])),
('additional', config_options.Type(list, default=[])),
)

def text_contrast(self, value, pref_dark):
Expand Down Expand Up @@ -290,6 +294,16 @@ def on_post_build(self, config, **kwargs):
for theme in self.themes_to_build:
pcolor, scolor = theme.split(',',1)
self.generate_theme(config, pcolor, '-'+pcolor.lstrip('#')+'-'+scolor.lstrip('#'), scolor)
if self.config.get('additional'):
try:
for additional in self.config['additional']:
pcolor = additional['theme_color']
scolor = additional['secondary_color']
name = '-'+pcolor.lstrip('#')+'-'+scolor.lstrip('#')
self.generate_theme(config, pcolor, name, scolor)
logger.info('Built additional color theme "w3-theme{name}".'.format(name=name))
except:
logger.info('Could not build additional color-themes')

def on_page_context(self, context, page, config, nav):
#get meta keys from pages
Expand Down

0 comments on commit e619726

Please sign in to comment.