SECTION 04 · 40 MIN READ & EXPLORE
Publish a generated portfolio
Build HTML from YAML and Jinja, then publish the output through GitLab Pages.
From data to a public portfolio
Build the site locally, change a player profile, then publish the generated output.
Your mission
- Build the site locally, change a player profile, then publish the generated output.
Download and extract the archive. Work inside 08-portfolio; upload its contents to the root of a GitLab project when a pipeline is involved.
Build locally, then publish
Inspect the inputs
Read
build.py, the player YAML, and the Jinja template. Find how the script chooses its profile and where it writes HTML.Generate the site
uv run --with pyyaml --with jinja2 build.py python3 -m http.server 8000 --directory publicVisit localhost:8000. Edit the profile data, rebuild, and compare the result.
Publish through CI
Push the extracted module contents, including
.gitlab-ci.yml, to the root of a practice GitLab project. Inspect the Pages job and use the URL shown by that project’s Pages settings. Stop the local HTTP server with Ctrl+C.
How to know it worked
- The generated HTML reflects a YAML change.
- The Pages job publishes the public directory.
Explore the files
build.py
import os
import yaml
import shutil
from jinja2 import Environment, FileSystemLoader
DATA_DIR = 'data'
TEMPLATE_DIR = 'templates'
STATIC_DIR = 'static'
OUTPUT_DIR = 'public'
def load_profiles():
profiles = []
for filename in os.listdir(DATA_DIR):
if filename.endswith('.yaml') or filename.endswith('.yml'):
with open(os.path.join(DATA_DIR, filename), 'r') as f:
profile = yaml.safe_load(f)
profiles.append(profile)
return profiles
def build():
# 1. Prepare Output Directory
if os.path.exists(OUTPUT_DIR):
shutil.rmtree(OUTPUT_DIR)
os.makedirs(OUTPUT_DIR)
# 2. Load Data
profiles = load_profiles()
# 3. Setup Jinja2
env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
template = env.get_template('index.html.j2')
# 4. Render Template
output_html = template.render(profiles=profiles)
with open(os.path.join(OUTPUT_DIR, 'index.html'), 'w') as f:
f.write(output_html)
# 5. Copy Static Assets
shutil.copytree(STATIC_DIR, os.path.join(OUTPUT_DIR, 'static'))
print(f"✅ Build complete! Output in '{OUTPUT_DIR}'")
if __name__ == "__main__":
build()hakimi.yaml
personal:
image: "https://img.a.transfermarkt.technology/portrait/big/398073-1672304327.jpg?lm=1"
name: "Achraf Hakimi"
title: "High-Availability Wing-Back and Systems Architect"
email: "a.hakimi@psg.fr"
phone: "+33 6 12 34 56 78"
github: "github.com/hakimi-turbo"
summary: "World-class right-back specializing in rapid deployment (sprints), defensive security (tackles), and high-availability assists. Proven track record in top-tier European leagues and international tournaments (CAN, World Cup)."
experience:
- role: "Senior Wing-Back"
company: "Paris Saint-Germain (PSG)"
location: "Paris, FR"
dates: "2021 -- Present"
details:
- "Architected right-flank attacks resulting in 15+ assists per season."
- "Maintained 99.9% uptime during Ligue 1 matches."
- "Collaborated with Mbappe-Microservices for rapid counter-attacks."
- role: "Defensive Engineer (Loan)"
company: "Inter Milan"
location: "Milan, IT"
dates: "2020 -- 2021"
details:
- "Deployed the 'Scudetto' release, winning the Serie A title."
- "Optimized defensive transitions under Antonio Conte's 3-5-2 framework."
- role: "Full-Stack Defender"
company: "Borussia Dortmund"
location: "Dortmund, DE"
dates: "2018 -- 2020"
details:
- "Developed speed protocols reaching 36.48 km/h (top speed record)."
- "Implemented cross-functional overlaps in the Bundesliga."
education:
- degree: "PhD in Pace and Precision"
institution: "Real Madrid Academy (La Fábrica)"
dates: "2006 -- 2017"
skills:
languages: "Arabic, Spanish, French, English, German"
tools: "Nike Mercurial, GPS Tracker, VAR Analysis"
infrastructure: "Right Wing, Right Midfield, Left Back (Legacy Support)"index.html.j2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Atlas Lions Portfolio</title>
<link rel="stylesheet" href="static/css/style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap" rel="stylesheet">
</head>
<body>
<header>
<div class="container">
<h1>Atlas Lions 🦁</h1>
<p>DevOps & Cloud Engineering Squad</p>
<button id="theme-toggle">🌙</button>
</div>
</header>
<main class="container">
<div class="grid">
{% for profile in profiles %}
<div class="card">
<div class="card-header">
<img src="{{ profile.personal.image }}" alt="{{ profile.personal.name }}" class="profile-img">
</div>
<div class="card-body">
<h2>{{ profile.personal.name }}</h2>
<p class="title">{{ profile.personal.title }}</p>
<div class="details">
<p><strong>Email:</strong> {{ profile.personal.email }}</p>
<p><strong>Phone:</strong> {{ profile.personal.phone }}</p>
<p><strong>Location:</strong> {{ profile.personal.location }}</p>
</div>
<div class="skills">
{% if profile.skills.tools %}
{% for tool in profile.skills.tools.split(',') %}
<span class="tag">{{ tool.strip() }}</span>
{% endfor %}
{% endif %}
</div>
</div>
</div>
{% endfor %}
</div>
</main>
<footer>
<p>© 2025 Atlas Lions. Built with GitLab CI/CD.</p>
</footer>
<script src="static/js/script.js"></script>
</body>
</html>.gitlab-ci.yml
default:
image: python:3.11-slim
before_script:
- cd $PROJECT_DIR
variables:
PROJECT_DIR: "."
pages:
stage: deploy
script:
- pip install pyyaml jinja2
- python build.py
pages: true
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == "main"Pause and predict
Why publish generated HTML rather than run the Python generator for each visitor?
Try your own explanation first. These notes stay on this page and are not saved or graded.
Show explanation
The generator runs during the build. The resulting static files can be served without a Python application process.
Take a moment to explain the idea in your own words.