Skip to content

Commit 3690aa8

Browse files
authored
feat: gh pages deployment (#14)
* feat: github pages deployment * docs: update readme * ci: update gh-pages pipeline * docs: update readme * docs: update readme
1 parent a221518 commit 3690aa8

File tree

5 files changed

+118
-3
lines changed

5 files changed

+118
-3
lines changed

.github/workflows/github-pages.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
name: Render & Publish Pages
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- master
9+
10+
defaults:
11+
run:
12+
shell: bash
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.13'
24+
25+
- name: Install Jinja2
26+
run: python3 -m pip install -U pip jinja2
27+
28+
- name: Render Templates
29+
run: python3 tools/render_template.py
30+
31+
- name: Upload static files as artifact
32+
id: deployment
33+
uses: actions/upload-pages-artifact@v3
34+
with:
35+
path: rendered_artifacts/
36+
37+
deploy:
38+
runs-on: ubuntu-latest
39+
environment:
40+
name: github-pages
41+
url: ${{ steps.deployment.outputs.page_url }}
42+
permissions:
43+
pages: write
44+
id-token: write
45+
needs: build
46+
steps:
47+
- name: Deploy to GitHub Pages
48+
id: deployment
49+
uses: actions/deploy-pages@v4
50+

.github/workflows/pipeline.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: Lint & Install Pipeline
23

34
on:
@@ -8,20 +9,18 @@ on:
89

910
jobs:
1011
build:
11-
1212
runs-on: ubuntu-22.04
1313
strategy:
1414
max-parallel: 4
1515
matrix:
1616
python-version: ["3.9", "3.10", "3.11", "3.12"]
17-
1817
steps:
1918
- uses: actions/checkout@v4
2019

2120
- uses: psf/black@stable
2221
name: Lint
2322
with:
24-
options: --check --line-length 120 .
23+
options: --check --line-length 79 .
2524

2625
- name: Set up Python ${{ matrix.python-version }}
2726
uses: actions/setup-python@v5
@@ -32,3 +31,4 @@ jobs:
3231
run: |
3332
python3 -m pip install --upgrade pip
3433
python3 -m pip install -r requirements.txt
34+

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ __pycache__/
55
*.log
66

77
env/
8+
9+
output.html
10+
rendered_artifacts/

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
If you'd like to use this repo as a template, all you need to do is fork
66
it and update `resume_config.toml` with your information accordingly.
77

8+
You should also update any static files to include your headshot if desired.
9+
10+
### GitHub Pages Deployment
11+
By default, this repo will publish to GitHub pages from the `main` or `master` branch.
12+
813
### Heroku Deployment
914
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
1015

tools/render_template.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Render HTML resume templates and copy static files to output directory.
3+
"""
4+
5+
import jinja2
6+
import tomllib
7+
import shutil
8+
from pathlib import Path
9+
10+
11+
def mock_url_for(endpoint, **kwargs):
12+
"""
13+
Mock url_for function for Jinja2 templates.
14+
Returns static file paths or endpoint routes.
15+
"""
16+
if endpoint == "static":
17+
filename = kwargs.get("filename", "")
18+
return f"/resume/static/{filename}"
19+
return f"/{endpoint}"
20+
21+
22+
def main():
23+
# Set up output directory
24+
output_dir = Path("rendered_artifacts")
25+
output_dir.mkdir(exist_ok=True)
26+
27+
# Set up static output directory
28+
static_output_dir = output_dir / "static"
29+
static_output_dir.mkdir(exist_ok=True)
30+
31+
# Copy static files to output directory
32+
static_dir = Path("static")
33+
if static_dir.exists():
34+
shutil.copytree(static_dir, static_output_dir, dirs_exist_ok=True)
35+
36+
# Set up Jinja2 environment
37+
template_dir = Path("templates/home")
38+
env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))
39+
env.globals["url_for"] = mock_url_for # Add mock url_for to Jinja2 globals
40+
41+
# Load the template
42+
template = env.get_template("index_template.html")
43+
44+
# Load data from TOML file
45+
with open("resume_config.toml", "rb") as file:
46+
resume_data = tomllib.load(file)
47+
48+
# Render the template with the data
49+
rendered_html = template.render(**resume_data)
50+
51+
# Save the rendered HTML to a file in output directory
52+
with open(output_dir / "index.html", "w") as outfile:
53+
outfile.write(rendered_html)
54+
55+
56+
if __name__ == "__main__":
57+
main()

0 commit comments

Comments
 (0)