Skip to content

Commit 56e5ad0

Browse files
committed
try build
1 parent c9c4f8a commit 56e5ad0

File tree

5 files changed

+67
-24
lines changed

5 files changed

+67
-24
lines changed

.github/workflows/static.yml

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
# Simple workflow for deploying static content to GitHub Pages
2-
name: Deploy static content to Pages
1+
name: Build and Deploy
32

43
on:
5-
# Runs on pushes targeting the default branch
64
push:
75
branches: ["main"]
8-
9-
# Allows you to run this workflow manually from the Actions tab
10-
workflow_dispatch:
11-
12-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
136
permissions:
147
contents: read
158
pages: write
169
id-token: write
1710

18-
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19-
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20-
concurrency:
21-
group: "pages"
22-
cancel-in-progress: false
23-
2411
jobs:
25-
# Single deploy job since we're just deploying
26-
deploy:
27-
environment:
28-
name: github-pages
29-
url: ${{ steps.deployment.outputs.page_url }}
12+
build:
3013
runs-on: ubuntu-latest
3114
steps:
3215
- name: Checkout
3316
uses: actions/checkout@v4
34-
- name: Setup Pages
35-
uses: actions/configure-pages@v5
17+
18+
- name: Setup Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.12' # Use the latest available Python version
22+
23+
- name: Install dependencies
24+
run: pip install --no-cache-dir -r requirements.txt
25+
26+
- name: Generate PDF from HTML
27+
run: python compile.py
28+
3629
- name: Upload artifact
3730
uses: actions/upload-pages-artifact@v3
38-
with:
39-
# Upload entire repository
40-
path: '.'
31+
32+
deploy:
33+
needs: build
34+
environment:
35+
name: github-pages
36+
url: ${{ steps.deployment.outputs.page_url }}
37+
runs-on: ubuntu-latest
38+
steps:
4139
- name: Deploy to GitHub Pages
4240
id: deployment
4341
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_site/index.html

compile.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import markdown
3+
import pdfkit
4+
5+
# Paths
6+
input_file = "README.md"
7+
output_dir = "_site"
8+
output_html = os.path.join(output_dir, "index.html")
9+
output_pdf = os.path.join(output_dir, "index.pdf")
10+
11+
def compile_markdown_to_pdf(input_path, output_html_path, output_pdf_path):
12+
# Check if the input file exists
13+
if not os.path.exists(input_path):
14+
raise FileNotFoundError(f"Input file '{input_path}' not found.")
15+
16+
# Create the output directory if it doesn't exist
17+
os.makedirs(os.path.dirname(output_html_path), exist_ok=True)
18+
19+
# Read the Markdown file
20+
with open(input_path, "r", encoding="utf-8") as md_file:
21+
markdown_content = md_file.read()
22+
23+
# Convert Markdown to HTML
24+
html_content = markdown.markdown(markdown_content)
25+
26+
# Write HTML to file
27+
with open(output_html_path, "w", encoding="utf-8") as html_file:
28+
html_file.write(html_content)
29+
30+
# Convert HTML to PDF
31+
pdfkit.from_file(output_html_path, output_pdf_path)
32+
print(f"Markdown compiled to PDF: {output_pdf_path}")
33+
34+
if __name__ == "__main__":
35+
compile_markdown_to_pdf(input_file, output_html, output_pdf)

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
compile:
3+
image: pandoc/latex
4+
volumes:
5+
- ./:/app/
6+
command: "pandoc README.md -o output.pdf"
7+
working_dir: /app/

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
markdown
2+
pdfkit

0 commit comments

Comments
 (0)