formatted imports
This commit is contained in:
parent
d8ca92dce6
commit
1221f43caf
13 changed files with 110 additions and 80 deletions
|
@ -1,14 +1,14 @@
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from zona.models import Item, ItemType
|
|
||||||
from zona.metadata import parse_metadata
|
|
||||||
from zona import markdown as zmd
|
|
||||||
from zona.templates import Templater
|
|
||||||
from zona.layout import Layout, discover_layout
|
|
||||||
from zona.config import ZonaConfig
|
|
||||||
from zona import util
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from rich import print
|
|
||||||
|
from zona import markdown as zmd
|
||||||
|
from zona import util
|
||||||
|
from zona.config import ZonaConfig
|
||||||
|
from zona.layout import Layout, discover_layout
|
||||||
from zona.log import get_logger
|
from zona.log import get_logger
|
||||||
|
from zona.metadata import parse_metadata
|
||||||
|
from zona.models import Item, ItemType
|
||||||
|
from zona.templates import Templater
|
||||||
|
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
|
|
||||||
|
@ -47,7 +47,9 @@ class ZonaBuilder:
|
||||||
destination=destination,
|
destination=destination,
|
||||||
url=str(destination.relative_to(layout.output)),
|
url=str(destination.relative_to(layout.output)),
|
||||||
)
|
)
|
||||||
if path.name.endswith(".md") and not path.is_relative_to(
|
if path.name.endswith(
|
||||||
|
".md"
|
||||||
|
) and not path.is_relative_to(
|
||||||
layout.root / "content" / "static"
|
layout.root / "content" / "static"
|
||||||
):
|
):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
@ -59,7 +61,7 @@ class ZonaBuilder:
|
||||||
and not self.config.build.include_drafts
|
and not self.config.build.include_drafts
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
if item.metadata.post == True:
|
if item.metadata.post:
|
||||||
item.post = True
|
item.post = True
|
||||||
elif item.metadata.post is None:
|
elif item.metadata.post is None:
|
||||||
# check if in posts dir?
|
# check if in posts dir?
|
||||||
|
@ -70,11 +72,13 @@ class ZonaBuilder:
|
||||||
item.copy = False
|
item.copy = False
|
||||||
name = destination.stem
|
name = destination.stem
|
||||||
if name == "index":
|
if name == "index":
|
||||||
item.destination = item.destination.with_suffix(
|
item.destination = (
|
||||||
".html"
|
item.destination.with_suffix(".html")
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
relative = path.relative_to(base).with_suffix("")
|
relative = path.relative_to(base).with_suffix(
|
||||||
|
""
|
||||||
|
)
|
||||||
name = relative.stem
|
name = relative.stem
|
||||||
item.destination = (
|
item.destination = (
|
||||||
layout.output
|
layout.output
|
||||||
|
@ -86,7 +90,9 @@ class ZonaBuilder:
|
||||||
layout.output
|
layout.output
|
||||||
)
|
)
|
||||||
item.url = (
|
item.url = (
|
||||||
"" if rel_url == Path(".") else rel_url.as_posix()
|
""
|
||||||
|
if rel_url == Path(".")
|
||||||
|
else rel_url.as_posix()
|
||||||
)
|
)
|
||||||
items.append(item)
|
items.append(item)
|
||||||
self.items = items
|
self.items = items
|
||||||
|
@ -112,7 +118,9 @@ class ZonaBuilder:
|
||||||
# write code highlighting stylesheet
|
# write code highlighting stylesheet
|
||||||
if self.config.markdown.syntax_highlighting.enabled:
|
if self.config.markdown.syntax_highlighting.enabled:
|
||||||
pygments_style = zmd.get_style_defs(self.config)
|
pygments_style = zmd.get_style_defs(self.config)
|
||||||
pygments_path = self.layout.output / "static" / "pygments.css"
|
pygments_path = (
|
||||||
|
self.layout.output / "static" / "pygments.css"
|
||||||
|
)
|
||||||
util.ensure_parents(pygments_path)
|
util.ensure_parents(pygments_path)
|
||||||
pygments_path.write_text(pygments_style)
|
pygments_path.write_text(pygments_style)
|
||||||
for item in self.item_map.values():
|
for item in self.item_map.values():
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
from typing import Annotated
|
|
||||||
import typer
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Annotated
|
||||||
|
|
||||||
|
import typer
|
||||||
|
|
||||||
from zona import server
|
from zona import server
|
||||||
from zona.builder import ZonaBuilder
|
from zona.builder import ZonaBuilder
|
||||||
from zona.layout import initialize_site
|
from zona.layout import initialize_site
|
||||||
from zona.log import setup_logging, get_logger
|
from zona.log import get_logger, setup_logging
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
|
@ -57,7 +59,9 @@ def build(
|
||||||
"""
|
"""
|
||||||
if draft:
|
if draft:
|
||||||
print("Option override: including drafts.")
|
print("Option override: including drafts.")
|
||||||
builder = ZonaBuilder(cli_root=root, cli_output=output, draft=draft)
|
builder = ZonaBuilder(
|
||||||
|
cli_root=root, cli_output=output, draft=draft
|
||||||
|
)
|
||||||
builder.build()
|
builder.build()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from dacite import from_dict
|
|
||||||
import yaml
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
from dacite import from_dict
|
||||||
|
|
||||||
from zona.log import get_logger
|
from zona.log import get_logger
|
||||||
|
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
|
@ -57,7 +59,9 @@ IGNORELIST = [".marksman.toml"]
|
||||||
class ZonaConfig:
|
class ZonaConfig:
|
||||||
base_url: str = "/"
|
base_url: str = "/"
|
||||||
# dictionary where key is name, value is url
|
# dictionary where key is name, value is url
|
||||||
sitemap: SitemapConfig = field(default_factory=lambda: {"Home": "/"})
|
sitemap: SitemapConfig = field(
|
||||||
|
default_factory=lambda: {"Home": "/"}
|
||||||
|
)
|
||||||
# list of globs relative to content that should be ignored
|
# list of globs relative to content that should be ignored
|
||||||
ignore: list[str] = field(default_factory=lambda: IGNORELIST)
|
ignore: list[str] = field(default_factory=lambda: IGNORELIST)
|
||||||
markdown: MarkdownConfig = field(default_factory=MarkdownConfig)
|
markdown: MarkdownConfig = field(default_factory=MarkdownConfig)
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
from dataclasses import asdict, dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from dataclasses import dataclass, asdict
|
|
||||||
from zona.config import ZonaConfig, find_config
|
|
||||||
from zona import util, log
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from zona import log, util
|
||||||
|
from zona.config import ZonaConfig, find_config
|
||||||
|
|
||||||
logger = log.get_logger()
|
logger = log.get_logger()
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,13 +19,18 @@ class Layout:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_input(
|
def from_input(
|
||||||
cls, root: Path, output: Path | None = None, validate: bool = True
|
cls,
|
||||||
|
root: Path,
|
||||||
|
output: Path | None = None,
|
||||||
|
validate: bool = True,
|
||||||
) -> "Layout":
|
) -> "Layout":
|
||||||
layout = cls(
|
layout = cls(
|
||||||
root=root.resolve(),
|
root=root.resolve(),
|
||||||
content=(root / "content").resolve(),
|
content=(root / "content").resolve(),
|
||||||
templates=(root / "templates").resolve(),
|
templates=(root / "templates").resolve(),
|
||||||
output=(root / "public").resolve() if not output else output,
|
output=(root / "public").resolve()
|
||||||
|
if not output
|
||||||
|
else output,
|
||||||
)
|
)
|
||||||
if validate:
|
if validate:
|
||||||
logger.debug("Validating site layout...")
|
logger.debug("Validating site layout...")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
from typing import Literal
|
|
||||||
from rich.logging import RichHandler
|
from rich.logging import RichHandler
|
||||||
|
|
||||||
_LOGGER_NAME = "zona"
|
_LOGGER_NAME = "zona"
|
||||||
|
|
|
@ -1,33 +1,30 @@
|
||||||
from collections.abc import Sequence
|
|
||||||
from rich import print
|
|
||||||
from markdown import Markdown
|
|
||||||
from typing import Any, override
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from pygments.formatters.html import HtmlFormatter
|
|
||||||
from zona.config import ZonaConfig
|
|
||||||
from zona.layout import Layout
|
|
||||||
|
|
||||||
from markdown.treeprocessors import Treeprocessor
|
|
||||||
from markdown.extensions.codehilite import CodeHiliteExtension
|
|
||||||
from markdown.extensions.smarty import SmartyExtension
|
|
||||||
from markdown.extensions.sane_lists import SaneListExtension
|
|
||||||
from pymdownx.inlinehilite import InlineHiliteExtension
|
|
||||||
from pymdownx.escapeall import EscapeAllExtension
|
|
||||||
from pymdownx.betterem import BetterEmExtension
|
|
||||||
from pymdownx.superfences import SuperFencesCodeExtension
|
|
||||||
from markdown.extensions.footnotes import FootnoteExtension
|
|
||||||
from markdown.extensions.attr_list import AttrListExtension
|
|
||||||
from markdown.extensions.def_list import DefListExtension
|
|
||||||
from markdown.extensions.tables import TableExtension
|
|
||||||
from markdown.extensions.abbr import AbbrExtension
|
|
||||||
from markdown.extensions.md_in_html import MarkdownInHtmlExtension
|
|
||||||
|
|
||||||
import xml.etree.ElementTree as etree
|
import xml.etree.ElementTree as etree
|
||||||
|
from collections.abc import Sequence
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any, override
|
||||||
|
|
||||||
|
from markdown import Markdown
|
||||||
|
from markdown.extensions.abbr import AbbrExtension
|
||||||
|
from markdown.extensions.attr_list import AttrListExtension
|
||||||
|
from markdown.extensions.codehilite import CodeHiliteExtension
|
||||||
|
from markdown.extensions.def_list import DefListExtension
|
||||||
|
from markdown.extensions.footnotes import FootnoteExtension
|
||||||
|
from markdown.extensions.md_in_html import MarkdownInHtmlExtension
|
||||||
|
from markdown.extensions.sane_lists import SaneListExtension
|
||||||
|
from markdown.extensions.smarty import SmartyExtension
|
||||||
|
from markdown.extensions.tables import TableExtension
|
||||||
|
from markdown.treeprocessors import Treeprocessor
|
||||||
|
from pygments.formatters.html import HtmlFormatter
|
||||||
|
from pymdownx.betterem import BetterEmExtension
|
||||||
|
from pymdownx.escapeall import EscapeAllExtension
|
||||||
|
from pymdownx.inlinehilite import InlineHiliteExtension
|
||||||
|
from pymdownx.superfences import SuperFencesCodeExtension
|
||||||
|
|
||||||
from zona import util
|
from zona import util
|
||||||
from zona.models import Item
|
from zona.config import ZonaConfig
|
||||||
|
from zona.layout import Layout
|
||||||
from zona.log import get_logger
|
from zona.log import get_logger
|
||||||
|
from zona.models import Item
|
||||||
|
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from dateutil import parser as date_parser
|
from pathlib import Path
|
||||||
|
|
||||||
|
import frontmatter
|
||||||
from dacite.config import Config
|
from dacite.config import Config
|
||||||
from dacite.core import from_dict
|
from dacite.core import from_dict
|
||||||
from dacite.exceptions import DaciteError
|
from dacite.exceptions import DaciteError
|
||||||
|
from dateutil import parser as date_parser
|
||||||
from yaml import YAMLError
|
from yaml import YAMLError
|
||||||
|
|
||||||
import zona.util
|
import zona.util
|
||||||
import frontmatter
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from pathlib import Path
|
|
||||||
from enum import Enum
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from enum import Enum
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from zona.metadata import Metadata
|
from zona.metadata import Metadata
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
import signal
|
|
||||||
import os
|
import os
|
||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
from rich import print
|
|
||||||
from types import FrameType
|
|
||||||
from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler
|
|
||||||
import threading
|
import threading
|
||||||
from typing import override
|
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
||||||
from watchdog.observers import Observer
|
|
||||||
from zona.builder import ZonaBuilder
|
|
||||||
from watchdog.events import FileSystemEventHandler, FileSystemEvent
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from types import FrameType
|
||||||
|
from typing import override
|
||||||
|
|
||||||
|
from watchdog.events import FileSystemEvent, FileSystemEventHandler
|
||||||
|
from watchdog.observers import Observer
|
||||||
|
|
||||||
|
from zona.builder import ZonaBuilder
|
||||||
from zona.log import get_logger
|
from zona.log import get_logger
|
||||||
|
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
|
@ -64,7 +65,7 @@ def run_http_server(dir: Path, host: str = "localhost", port: int = 8000):
|
||||||
server_address=(host, port), RequestHandlerClass=handler
|
server_address=(host, port), RequestHandlerClass=handler
|
||||||
)
|
)
|
||||||
logger.info(f"Serving {dir} at http://{host}:{port}")
|
logger.info(f"Serving {dir} at http://{host}:{port}")
|
||||||
logger.info(f"Exit with <c-c>")
|
logger.info("Exit with <c-c>")
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||||
|
|
||||||
from zona.config import ZonaConfig
|
from zona.config import ZonaConfig
|
||||||
from zona.models import Item
|
|
||||||
from zona.markdown import md_to_html
|
from zona.markdown import md_to_html
|
||||||
|
from zona.models import Item
|
||||||
|
|
||||||
|
|
||||||
def get_header(template_dir: Path) -> str | None:
|
def get_header(template_dir: Path) -> str | None:
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
from importlib.resources.abc import Traversable
|
|
||||||
from typing import NamedTuple
|
|
||||||
from rich import print
|
|
||||||
from importlib import resources
|
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
import string
|
||||||
|
from importlib import resources
|
||||||
|
from importlib.resources.abc import Traversable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import copy2
|
from shutil import copy2
|
||||||
import string
|
from typing import NamedTuple
|
||||||
|
|
||||||
|
|
||||||
class ZonaResource(NamedTuple):
|
class ZonaResource(NamedTuple):
|
||||||
|
@ -26,7 +25,8 @@ def get_resources(subdir: str) -> list[ZonaResource]:
|
||||||
else:
|
else:
|
||||||
out.append(
|
out.append(
|
||||||
ZonaResource(
|
ZonaResource(
|
||||||
name=f"{subdir}/{path}", contents=item.read_text()
|
name=f"{subdir}/{path}",
|
||||||
|
contents=item.read_text(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -65,8 +65,11 @@ def normalize_url(url: str) -> str:
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
def should_ignore(path: Path, patterns: list[str], base: Path) -> bool:
|
def should_ignore(
|
||||||
|
path: Path, patterns: list[str], base: Path
|
||||||
|
) -> bool:
|
||||||
rel_path = path.relative_to(base)
|
rel_path = path.relative_to(base)
|
||||||
return any(
|
return any(
|
||||||
fnmatch.fnmatch(str(rel_path), pattern) for pattern in patterns
|
fnmatch.fnmatch(str(rel_path), pattern)
|
||||||
|
for pattern in patterns
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import pytest
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from zona.metadata import Metadata
|
|
||||||
from zona.builder import split_metadata, discover, build
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from zona.builder import build, discover, split_metadata
|
||||||
|
from zona.metadata import Metadata
|
||||||
|
|
||||||
|
|
||||||
def test_split_metadata(tmp_path: Path):
|
def test_split_metadata(tmp_path: Path):
|
||||||
content = """---
|
content = """---
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from zona import util
|
from zona import util
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue