Update build script and templates for new org structure
This commit is contained in:
parent
cedd73996f
commit
6cfd6146e8
122
build.py
122
build.py
@ -0,0 +1,122 @@
|
|||||||
|
import argparse
|
||||||
|
import datetime
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import NamedTuple
|
||||||
|
from typing import Optional
|
||||||
|
from typing import Sequence
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
import jinja2
|
||||||
|
import marshmallow as msh
|
||||||
|
import ruamel.yaml
|
||||||
|
|
||||||
|
|
||||||
|
yaml = ruamel.yaml.YAML(typ="safe")
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class MediaContainer:
|
||||||
|
title: str
|
||||||
|
asset: str
|
||||||
|
anchor: Optional[Union[str, int]] = None
|
||||||
|
source: Optional[str] = None
|
||||||
|
content: Optional[str] = None
|
||||||
|
hide_source: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
class MediaSerializer(msh.Schema):
|
||||||
|
title = msh.fields.String()
|
||||||
|
asset = msh.fields.URL()
|
||||||
|
anchor = msh.fields.String(required=False)
|
||||||
|
source = msh.fields.URL(required=False)
|
||||||
|
content = msh.fields.String(required=False)
|
||||||
|
hide_source = msh.fields.Boolean(required=False)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class LinkContainer:
|
||||||
|
link: str
|
||||||
|
title: Optional[str] = None
|
||||||
|
icon: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class LinkSerializer(msh.Schema):
|
||||||
|
link = msh.fields.URL()
|
||||||
|
title = msh.fields.String(required=False)
|
||||||
|
icon = msh.fields.String(required=False)
|
||||||
|
|
||||||
|
|
||||||
|
class Location(NamedTuple):
|
||||||
|
title: str
|
||||||
|
link: str
|
||||||
|
|
||||||
|
|
||||||
|
class LocationSeralizer(msh.Schema):
|
||||||
|
title = msh.fields.String()
|
||||||
|
link = msh.fields.URL()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class PostContainer:
|
||||||
|
title: str
|
||||||
|
location: Location
|
||||||
|
date: datetime.date
|
||||||
|
banner: str
|
||||||
|
media: Sequence[MediaContainer]
|
||||||
|
links: Sequence[LinkContainer] = ()
|
||||||
|
slug: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
class PostSerializer(msh.Schema):
|
||||||
|
|
||||||
|
title = msh.fields.String()
|
||||||
|
location = msh.fields.Nested(LocationSeralizer)
|
||||||
|
date = msh.fields.Date()
|
||||||
|
banner = msh.fields.URL()
|
||||||
|
slug = msh.fields.String(required=False)
|
||||||
|
links = msh.fields.List(msh.fields.Nested(LinkSerializer), required=False)
|
||||||
|
media = msh.fields.List()
|
||||||
|
|
||||||
|
|
||||||
|
def get_args() -> argparse.Namespace:
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
"-c", "--check", action="store_true", help="Check the config without building"
|
||||||
|
)
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
cwd = Path.cwd().resolve()
|
||||||
|
output = cwd / "explore"
|
||||||
|
|
||||||
|
with (cwd / "config.yaml").open() as infile:
|
||||||
|
config = yaml.load(infile)
|
||||||
|
|
||||||
|
env = jinja2.Environment(
|
||||||
|
loader=jinja2.FileSystemLoader(str(cwd / "templates")),
|
||||||
|
autoescape=jinja2.select_autoescape(["html", "xml"]),
|
||||||
|
)
|
||||||
|
|
||||||
|
if not output.exists():
|
||||||
|
output.mkdir()
|
||||||
|
|
||||||
|
index = env.get_template("index.html.j2").render(config=config)
|
||||||
|
|
||||||
|
with (output / "index.html").open("w") as outfile:
|
||||||
|
outfile.write(index)
|
||||||
|
|
||||||
|
post_template = env.get_template("post.html.j2")
|
||||||
|
for post_data in config["posts"]:
|
||||||
|
post = post_template.render(post=post_data)
|
||||||
|
with (output / f"{post_data['slug']}.html").open("w") as outfile:
|
||||||
|
outfile.write(post)
|
||||||
|
|
||||||
|
nginx = env.get_template("nginx.conf.d.j2").render(config=config)
|
||||||
|
with (cwd / "nginx.conf").open("w") as outfile:
|
||||||
|
outfile.write(nginx)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@ -30,22 +30,23 @@
|
|||||||
<meta name="twitter:image" content="https://cdn.enp.one/img/backgrounds/cl-photo-boston.jpg">
|
<meta name="twitter:image" content="https://cdn.enp.one/img/backgrounds/cl-photo-boston.jpg">
|
||||||
<meta name="twitter:image:alt" content="All Around Here">
|
<meta name="twitter:image:alt" content="All Around Here">
|
||||||
|
|
||||||
<title>Explore All Around Here</title>
|
<title>{{ config.title }}</title>
|
||||||
<link rel="shortcut icon" href="https://cdn.enp.one/img/logos/aah-b-sm.png">
|
<link rel="shortcut icon" href="https://cdn.enp.one/img/logos/aah-b-sm.png">
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="https://cdn.enp.one/img/logos/aah-b-sm.png">
|
<link rel="apple-touch-icon" sizes="180x180" href="https://cdn.enp.one/img/logos/aah-b-sm.png">
|
||||||
<link rel="icon" type="image/png" sizes="32x32" href="https://cdn.enp.one/img/logos/aah-b-sm.png" >
|
<link rel="icon" type="image/png" sizes="32x32" href="https://cdn.enp.one/img/logos/aah-b-sm.png" >
|
||||||
<link rel="icon" type="image/png" sizes="16x16" href="https://cdn.enp.one/img/logos/aah-b-sm.png">
|
<link rel="icon" type="image/png" sizes="16x16" href="https://cdn.enp.one/img/logos/aah-b-sm.png">
|
||||||
|
{% for style in config.assets.css %}
|
||||||
<link rel="stylesheet" href="../css/explore.css"/>
|
<link rel="stylesheet" href="http{{ 's' if config.https else '' }}://{{ config.site }}/{{ style }}"/>
|
||||||
|
{% endfor %}
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"
|
href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"
|
||||||
integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/"
|
integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/"
|
||||||
crossorigin="anonymous"
|
crossorigin="anonymous"
|
||||||
/>
|
/>
|
||||||
|
{% for script in config.assets.js %}
|
||||||
<script type="text/javascript" src="../js/custom.js"></script>
|
<script type="text/javascript" src="http{{ 's' if config.https else '' }}://{{ config.site }}/{{ script }}"></script>
|
||||||
|
{% endfor %}
|
||||||
<noscript><style>.nojs { display: none; }</style></noscript>
|
<noscript><style>.nojs { display: none; }</style></noscript>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -57,13 +58,13 @@
|
|||||||
<div id="toggle-description" class="nojs"><i class="fas fa-paragraph"></i></div>
|
<div id="toggle-description" class="nojs"><i class="fas fa-paragraph"></i></div>
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<div id="header"><h1>Explore All Around Here</h1></div>
|
<div id="header"><h1>{{ config.title }}</h1></div>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{% for post in config.posts %}
|
{% for post in config.posts %}
|
||||||
<li class="article">
|
<li class="article">
|
||||||
<div class="article-banner" style="background-image: url('{{ post.banner }}');">
|
<div class="article-banner" style="background-image: url('{{ post.banner }}');">
|
||||||
<a href="{{ post.slug }}" class="article-content">
|
<a href="http{{ 's' if config.https else '' }}://{{ config.site }}/{{ config.path.output }}/{{ post.slug }}/" class="article-content">
|
||||||
<h2>{{ post.title }}</h2>
|
<h2>{{ post.title }}</h2>
|
||||||
<p>
|
<p>
|
||||||
<i class="fas fa-map-marker-alt"></i>{{ post.location }}
|
<i class="fas fa-map-marker-alt"></i>{{ post.location }}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
location = http{{ 's' if config.https else '' }}://{{ config.site }}/robots.txt {
|
||||||
|
allow all;
|
||||||
|
log_not_found off;
|
||||||
|
access_log off;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = http{{ 's' if config.https else '' }}://{{ config.site }}/{{ config.path.output }}/ {
|
||||||
|
index index.html
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~* http{{ 's' if config.https else '' }}://{{ config.site }}/{{ config.path.output }}/(.*)/ {
|
||||||
|
if ($request_uri ~ ^/(.*)\.html) {
|
||||||
|
return 302 http{{ 's' if config.https else '' }}://{{ config.site }}/{{ config.path.output }}/$1/;
|
||||||
|
}
|
||||||
|
try_files $uri $uri.html $uri/ =404;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user