Skip to content

Commit f77f736

Browse files
committed
social generation stuff, digital meetup only atm
1 parent ddcb0fa commit f77f736

File tree

6 files changed

+356
-0
lines changed

6 files changed

+356
-0
lines changed

.github/workflows/deploy.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build and Deploy
2+
on: [push]
3+
jobs:
4+
build-and-deploy:
5+
concurrency: ci-${{ github.ref }}
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout 🛎️
9+
uses: actions/checkout@v3
10+
11+
- name: Install and Build 🔧
12+
run: |
13+
sudo apt-get update && sudo apt-get install inkscape
14+
pip install -r requirements.txt
15+
python socials.py
16+
17+
- name: Deploy 🚀
18+
uses: JamesIves/[email protected]
19+
with:
20+
branch: gh-pages
21+
folder: build

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
venv/

posters.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Posters for social events
2+
[digital_meetup.meta]
3+
template = "./templates/digital-meetup-poster.svg"
4+
5+
[digital_meetup]
6+
instances = [
7+
{year = "2022", date = "April 6th", time = "7pm"},
8+
{year = "2022", date = "April 14th", time = "7pm"},
9+
{year = "2022", date = "April 20th", time = "7pm"},
10+
{year = "2022", date = "April 28th", time = "7pm"},
11+
]

requirements.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
chevron==0.14.0
2+
click==8.1.2
3+
Jinja2==3.1.1
4+
MarkupSafe==2.1.1
5+
pydantic==1.9.0
6+
toml==0.10.2
7+
typing-extensions==4.1.1

socials.py

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
from pathlib import Path
2+
import shutil
3+
from typing import List
4+
import subprocess
5+
import tempfile
6+
7+
import chevron
8+
import click
9+
import toml
10+
from pydantic import BaseModel
11+
from jinja2 import Environment, PackageLoader, select_autoescape
12+
from jinja2 import Template
13+
14+
def run_inkscape(input: str, output: str):
15+
click.echo(f"Running inkscape to produce {output}")
16+
subprocess.run(['inkscape', '--export-type=png', f'--export-filename={output}', input])
17+
18+
19+
class DigitalMeetup(BaseModel):
20+
class Meta(BaseModel):
21+
template: str
22+
23+
class Instance(BaseModel):
24+
year: str
25+
date: str
26+
time: str
27+
28+
meta: Meta
29+
instances: List[Instance]
30+
31+
class Posters(BaseModel):
32+
digital_meetup: DigitalMeetup
33+
34+
35+
class Output(BaseModel):
36+
title: str
37+
path: str
38+
39+
40+
def handle_digital_meetup(digital_meetup: DigitalMeetup) -> List[Output]:
41+
with open(digital_meetup.meta.template, 'r') as reader:
42+
template = reader.read()
43+
44+
outputs = []
45+
46+
for instance in digital_meetup.instances:
47+
with tempfile.NamedTemporaryFile(suffix=".svg") as fp:
48+
rendered = chevron.render(
49+
template=template,
50+
data=instance
51+
)
52+
parent_dir = f"./build/{instance.year}/digital-meetup/"
53+
Path(parent_dir).mkdir(parents=True, exist_ok=True)
54+
55+
fp.write(rendered.encode('utf-8'))
56+
57+
output_filename = f"{parent_dir}digital-meetup-{instance.year}-{instance.date}-{instance.time}.png"
58+
run_inkscape(fp.name, output_filename)
59+
60+
outputs.append(Output(
61+
title=f"Digital Meetup ({instance.year}) {instance.date} @ {instance.time}",
62+
path=output_filename.lstrip("./build")
63+
))
64+
65+
return outputs
66+
67+
@click.command()
68+
def socials():
69+
"""Generates social content"""
70+
click.echo("Generating socials content...")
71+
72+
with open('posters.toml', 'r') as reader:
73+
posters_toml_string = reader.read()
74+
75+
posters_toml = toml.loads(posters_toml_string)
76+
77+
posters = Posters(**posters_toml)
78+
79+
outputs = [
80+
*handle_digital_meetup(posters.digital_meetup)
81+
]
82+
83+
template = Template("""
84+
<!DOCTYPE html>
85+
<html>
86+
<head>
87+
<title>CTSNL Socials</title>
88+
<style>
89+
body {
90+
font-family: sans-serif;
91+
margin: 4rem;
92+
}
93+
.output {
94+
margin: 2rem 0;
95+
}
96+
.output img {
97+
max-width: 40rem;
98+
}
99+
</style>
100+
<head>
101+
<body>
102+
<h1>CTSNL Socials</h1>
103+
<p>Automagically generating social assets</p>
104+
<a href="https://github.com/CTS-NL/Socials">https://github.com/CTS-NL/Socials</a>
105+
{% for output in outputs %}
106+
<div class="output">
107+
<h2>{{ output.title }}</h2>
108+
<img src="{{ output.path }}" />
109+
</div>
110+
{% endfor %}
111+
</body>
112+
</html>
113+
""").render(outputs=outputs)
114+
115+
Path("./build/index.html").write_text(template)
116+
Path("./build/posters.json").write_text(posters.json(indent=2))
117+
shutil.copytree("./templates", "./build/templates", dirs_exist_ok=True)
118+
119+
click.echo("Generating social content")
120+
121+
if __name__ == '__main__':
122+
socials()

templates/digital-meetup-poster.svg

+193
Loading

0 commit comments

Comments
 (0)