Skip to content

Date formatting #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/generator-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Github Actions workflow file. Uses Docker Container.

name: DataTribe's Weekly Post Convertor (Docker)

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Build Docker Image
run: docker build -t wp-convert -f ver2_conversion/Dockerfile .

- name: Run Container & Generate PDFs
run: docker run --rm -v ${{ github.workspace }}:/app wp-convert

- name: Upload PDFs as Artifact
uses: actions/upload-artifact@v4
with:
name: pdfs
path: "**/*.pdf"
44 changes: 44 additions & 0 deletions ver1_conversion/gh-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Ver1 Github Action Workflow File.

name: DataTribe Weekly Post Generator

on:
push:
branches:
- main

jobs:
data-tribe-weekly-post-generator:
runs-on: ubuntu-latest

container: debian:bookworm-slim

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install dependencies
run: |
apt-get update
apt-get install -y --no-install-recommends pandoc wkhtmltopdf
- name: Find and Convert Markdown to HTML with Template
run: |
ROOT_DIR=$(pwd)
find . -type f -name "*.md" | while read -r md_file; do
folder=$(dirname "$md_file")
filename=$(basename "$md_file" .md)
html_file="${folder}/${filename}.html"
pdf_file="${folder}/${filename}.pdf"

echo "Processing $md_file -> $html_file -> $pdf_file"

pandoc "$md_file" -o "$html_file" --template="$ROOT_DIR/template.html" --css="$ROOT_DIR/style.css" --metadata title="$filename"

wkhtmltopdf --enable-local-file-access "$html_file" "$pdf_file"
done

- name: Upload PDFs as Artifacts
uses: actions/upload-artifact@v4
with:
name: markdown-pdfs
path: "**/*.pdf"
File renamed without changes
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions ver2_conversion/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Slimmer base image.
FROM node:20-slim

WORKDIR /app

# Install necessary depencies.
RUN apt-get update && apt-get install -y --no-install-recommends \
libnss3 \
libxss1 \
libatk-bridge2.0-0 \
libgtk-3-0 \
libasound2 \
libgbm1 \
fonts-liberation \
libappindicator3-1 \
libxtst6 \
xdg-utils \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Install md-to-pdf.
RUN npm install -g md-to-pdf

# Copy ONLY necessary files first: Optimized use of cache.
COPY convert/config.js /app/ver2_conversion/config.js

# Copy rest of the files.
COPY . /app

# Run conversion with Puppeteer flags.
CMD ["sh", "-c", "for md_file in **/*.md; do [ -f \"$md_file\" ] || continue; pdf_file=\"${md_file%.md}.pdf\"; md-to-pdf \"$md_file\" --config-file /app/ver2_conversion/config.js --launch-options '{\"args\": [\"--no-sandbox\", \"--disable-setuid-sandbox\"]}'; done"]
8 changes: 5 additions & 3 deletions config.js → ver2_conversion/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const fs = require('fs');

const logoBase64 = fs.readFileSync('./logo.svg', { encoding: 'base64' });
const logoBase64 = fs.readFileSync('./ver2_conversion/logo.svg', { encoding: 'base64' });
const logoDataUrl = `data:image/svg+xml;base64,${logoBase64}`;


module.exports = {
stylesheet: ['./layout.css'],
stylesheet: ['./ver2_conversion/layout.css'],
marked_options: {
headerIds: true,
smartypants: true,
Expand Down Expand Up @@ -65,7 +65,9 @@ module.exports = {
</style>
<section>
<span style='font-size: 9pt; text-transform: none; height: 40px; text-align: center; align-items: center;'>
PDF generated on: ${new Date().toLocaleDateString()}</span>

PDF generated on: ${new Date().toLocaleDateString('fi-FI')}</span>

</section>
`,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Standard GitHub Actions workflow file. No Docker Container.

name: DataTribe's Weekly Post Convertor
on:
push:
Expand Down
File renamed without changes.
File renamed without changes