-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add gh-pages build script for pygments css
- Loading branch information
1 parent
465e326
commit 6704a3d
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- "main" | ||
|
||
jobs: | ||
build: | ||
runs-on: "ubuntu-latest" | ||
|
||
steps: | ||
- uses: "actions/checkout@v4" | ||
- uses: "actions/setup-python@v5" | ||
with: | ||
python-version: "3.x" | ||
- uses: "actions/setup-node@v4" | ||
with: | ||
node-version: "latest" | ||
- run: "pip install catppuccin[pygments]" | ||
- run: "scripts/build-gh-pages" | ||
- run: "npx lightningcss-cli ./gh-pages/pygments/*.css --output-dir ./gh-pages/pygments/" | ||
- uses: "peaceiris/actions-gh-pages@v3" | ||
with: | ||
enable_jekyll: false | ||
github_token: "${{ secrets.GITHUB_TOKEN }}" | ||
publish_branch: "gh-pages" | ||
publish_dir: "./gh-pages" | ||
user_email: "github-actions[bot]@users.noreply.github.com" | ||
user_name: "github-actions[bot]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python | ||
import re | ||
from pathlib import Path | ||
|
||
from pygments.formatters.html import HtmlFormatter | ||
|
||
from catppuccin import PALETTE | ||
from catppuccin.extras.pygments import ( | ||
FrappeStyle, | ||
LatteStyle, | ||
MacchiatoStyle, | ||
MochaStyle, | ||
) | ||
|
||
OUT_DIR = Path("gh-pages") | ||
PYGMENTS_DIR = OUT_DIR / "pygments" | ||
|
||
PYGMENTS_STYLES = { | ||
PALETTE.latte.identifier: LatteStyle, | ||
PALETTE.frappe.identifier: FrappeStyle, | ||
PALETTE.macchiato.identifier: MacchiatoStyle, | ||
PALETTE.mocha.identifier: MochaStyle, | ||
} | ||
|
||
|
||
PADDING_PAT = re.compile(r" padding-(?:left|right): \d+px;") | ||
|
||
|
||
def write(content: str, path: Path) -> None: | ||
path.parent.mkdir(parents=True, exist_ok=True) | ||
path.write_text(content) | ||
|
||
|
||
def postprocess_css(content: str) -> str: | ||
return PADDING_PAT.sub("", content) | ||
|
||
|
||
def flavor_css(flavor: str) -> str: | ||
style = PYGMENTS_STYLES[flavor] | ||
formatter = HtmlFormatter(style=style) | ||
return formatter.get_style_defs() | ||
|
||
|
||
def variable_css() -> str: | ||
flavor = PALETTE.latte | ||
css = flavor_css(flavor.identifier) | ||
for color in flavor.colors: | ||
css = css.replace(color.hex, f"var(--ctp-{color.identifier})") | ||
return css | ||
|
||
|
||
def build_css() -> None: | ||
# build individual CSS files for each flavor | ||
for flavor in PALETTE: | ||
filename = f"ctp-{flavor.identifier}.css" | ||
path = PYGMENTS_DIR / filename | ||
write(postprocess_css(flavor_css(flavor.identifier)), path) | ||
|
||
# build a variable CSS file | ||
path = PYGMENTS_DIR / "ctp-variable.css" | ||
write(postprocess_css(variable_css()), path) | ||
|
||
|
||
if __name__ == "__main__": | ||
build_css() |