Skip to content

Commit

Permalink
add chroma_reset.py
Browse files Browse the repository at this point in the history
  • Loading branch information
HidegonSan committed Sep 3, 2023
1 parent e9aacc6 commit 31ffab5
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 9 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ hugo.linux
*.vsix

# Personal
memo.md
update.sh
/memo.txt
/content/posts/__TEST_ARTICLE_FOR_DEBUG
/content/posts/__test_*
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ chroma:
hugo gen chromastyles --style=monokai > ./assets/css/extended/chroma_dark.css
hugo gen chromastyles --style=monokailight > ./assets/css/extended/chroma_light.css
sed -i 's/.chroma/.dark .chroma/g' ./assets/css/extended/chroma_dark.css
python chroma_reset.py

update:
git submodule update --remote --merge
Expand Down
5 changes: 3 additions & 2 deletions assets/css/extended/chroma_reset.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Reset Chroma styles for monokai and monokailight */
/* Reset Chroma styles for light/dark theme*/
/* Unset colors between light/dark */


/* for dark */
/* Name */ .dark .chroma .n { color: unset; }
/* NameBuiltin */ .dark .chroma .nb { color: unset; }
/* NameBuiltinPseudo */ .dark .chroma .bp { color: unset; }
Expand All @@ -17,6 +17,7 @@
/* NameVariableMagic */ .dark .chroma .vm { color: unset; }
/* Punctuation */ .dark .chroma .p { color: unset; }

/* for light */
/* GenericDeleted */ .chroma .gd { color: unset; }
/* GenericInserted */ .chroma .gi { color: unset; }
/* GenericSubheading */ .chroma .gu { color: unset; }
51 changes: 51 additions & 0 deletions chroma_reset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
dark_color_unset = []
light_color_unset = []


with open("./assets/css/extended/chroma_dark.css", "r") as file_dark:
for line_dark in file_dark.readlines():
name = line_dark.split("*/")[0][3:].strip()
tmp = line_dark.split(".dark .chroma ")
if 2 <= len(tmp):
class_name = tmp[1].split(" {")[0]
else:
continue
is_color_unset = line_dark.find("color: ") == -1
if is_color_unset:
dark_color_unset.append([name, class_name])


with open("./assets/css/extended/chroma_light.css", "r") as file_light:
for line_dark in file_light.readlines():
name = line_dark.split("*/")[0][3:].strip()
tmp = line_dark.split(".chroma ")
if 2 <= len(tmp):
class_name = tmp[1].split(" {")[0]
else:
continue
is_color_unset = line_dark.find("color: ") == -1
if is_color_unset:
if not any([name == i[0] for i in dark_color_unset]):
light_color_unset.append([name, class_name])
else:
index = [name == i[0] for i in dark_color_unset].index(True)
dark_color_unset.pop(index)


output = """/* Reset Chroma styles for light/dark theme*/
/* Unset colors between light/dark */
/* for dark */
"""

for i in sorted(dark_color_unset):
output += f"/* {i[0]} */ .dark .chroma {i[1]} " + "{ color: unset; }\n"

output += "\n/* for light */\n"

for i in sorted(light_color_unset):
output += f"/* {i[0]} */ .chroma {i[1]} " + "{ color: unset; }\n"


with open("./assets/css/extended/chroma_reset.css", "w+") as fw:
fw.write(output)
4 changes: 2 additions & 2 deletions layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
id="{{ first 6 (shuffle (seq 1 500)) }}"
src="{{ .Destination | safeURL }}"
alt="{{ .PlainText }}"
{{ with .Title}}
{{ with .Title }}
title="{{ . }}"
{{ end }}
onclick="open_image_modal(this.id)"
Expand Down Expand Up @@ -54,7 +54,7 @@

{{- end -}}

{{/* end of local resources*/}}
{{/* end of local resources */}}
{{- end -}}


Expand Down
8 changes: 5 additions & 3 deletions layouts/_default/_markup/render-link.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

<a
href="{{ .Destination | safeURL }}"
{{ with .Title }} title="{{ . }}"{{ end }}
{{ with .Title }}
title="{{ . }}"
{{ end }}
{{ if strings.HasPrefix .Destination "http" }}
target="_blank" rel="noopener, noreferrer, nofollow"
{{ end }}
{{ end }}
>
{{ .Text | safeHTML}}
{{ .Text | safeHTML }}
</a>

0 comments on commit 31ffab5

Please sign in to comment.