Add support for extra static file assets in templates
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from omicron.ssg.output.output import Output
|
||||
from omicron.ssg.output.content import Content, ContentError
|
||||
from omicron.ssg.output.factory import create_content, is_content
|
||||
from omicron.ssg.output.file import File
|
||||
from omicron.ssg.output.index import Index, discover_index
|
||||
from omicron.ssg.output.memory import Memory
|
||||
from omicron.ssg.output.tags import Tags, discover_tags
|
||||
@@ -11,6 +12,7 @@ __all__ = [
|
||||
"ContentError",
|
||||
"create_content",
|
||||
"is_content",
|
||||
"File",
|
||||
"Index",
|
||||
"discover_index",
|
||||
"Memory",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import logging
|
||||
import shutil
|
||||
from typing import TYPE_CHECKING
|
||||
from omicron.ssg.output.output import Output
|
||||
from pathlib import Path
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from omicron.ssg.site import Site # for static checking with mypy
|
||||
else:
|
||||
Site = "omicron.ssg.site.Site" # for runtime checking with beartype
|
||||
|
||||
|
||||
class File(Output):
|
||||
def __init__(self, uri: str, source: Path):
|
||||
super().__init__(uri)
|
||||
self.source = source
|
||||
|
||||
def write(self, site: Site) -> None:
|
||||
dest = site.output_path / self.uri
|
||||
dest.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(self.source, dest)
|
||||
log.debug("Copied %s -> %s", self.source, dest)
|
||||
+15
-1
@@ -8,6 +8,7 @@ from omicron.ssg.output import (
|
||||
ContentError,
|
||||
is_content,
|
||||
create_content,
|
||||
File,
|
||||
Memory,
|
||||
discover_index,
|
||||
discover_tags,
|
||||
@@ -104,9 +105,22 @@ class Site:
|
||||
tags.sort(key=lambda x: x[1], reverse=True)
|
||||
self.tags_by_count = tags
|
||||
|
||||
def discover_assets(self) -> None:
|
||||
assets_path = self.template_path / "assets"
|
||||
if not assets_path.is_dir():
|
||||
return
|
||||
for file in assets_path.rglob("*"):
|
||||
if file.is_file():
|
||||
uri = "assets/" + file.relative_to(assets_path).as_posix()
|
||||
asset = File(uri, file)
|
||||
self.add_by_uri(asset)
|
||||
self.other_outputs.append(asset)
|
||||
log.debug("Discovered template asset %s", uri)
|
||||
|
||||
def discover(self) -> None:
|
||||
log.info("Discovering content...")
|
||||
pygments = Memory("pygments.css", highlight_style())
|
||||
self.discover_assets()
|
||||
pygments = Memory("assets/pygments.css", highlight_style())
|
||||
self.other_outputs.append(pygments)
|
||||
self.add_by_uri(pygments)
|
||||
content_path = self.site_path / "content"
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 62.5%;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 1.8rem;
|
||||
font-family: sans-serif;
|
||||
line-height: 1.6;
|
||||
max-width: 65rem;
|
||||
margin: 0 auto;
|
||||
padding: 1rem;
|
||||
color: #222;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0066cc;
|
||||
}
|
||||
|
||||
pre {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}{{ site.name }}{% endblock %}</title>
|
||||
<link rel="stylesheet" href="{{ site.base_dir }}pygments.css">
|
||||
<link rel="stylesheet" href="{{ site.base_dir }}assets/style.css">
|
||||
<link rel="stylesheet" href="{{ site.base_dir }}assets/pygments.css">
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user