Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ build/
dist/
.vscode/.ropeproject/
.cache
venv/
37 changes: 19 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN \
apk add --no-cache \
git \
git-fast-import \
git-lfs \
openssh \
cairo-dev \
freetype-dev \
libffi-dev \
jpeg-dev \
libpng-dev \
zlib-dev \
&& apk add --no-cache --virtual .build gcc musl-dev \
&& apk add --no-cache --upgrade bash \
&& pip install --upgrade pip \
&& pip install --no-cache-dir mkdocs-material mike pillow cairosvg

WORKDIR /tmp
COPY mkdocs_simple_plugin mkdocs_simple_plugin
COPY README.md README.md
COPY VERSION VERSION
COPY setup.py setup.py
COPY pyproject.toml pyproject.toml

RUN \
apk add --no-cache \
git \
git-fast-import \
git-lfs \
openssh \
cairo-dev \
freetype-dev \
libffi-dev \
jpeg-dev \
libpng-dev \
zlib-dev \
&& apk add --no-cache --virtual .build gcc musl-dev \
&& apk add --no-cache --upgrade bash \
&& pip install --upgrade pip \
&& pip install --no-cache-dir mkdocs-material mike pillow cairosvg \
&& pip install --no-cache-dir . \
RUN pip install --no-cache-dir . \
&& rm -rf /tmp/*

WORKDIR /docs
Expand All @@ -42,4 +43,4 @@ COPY docker/deploy.sh /usr/local/bin/
COPY docker/entrypoint.sh /usr/local/bin/
ENTRYPOINT ["entrypoint.sh"]

CMD ["mkdocs_simple_gen", "--serve", "--", "-a", "0.0.0.0:8000"]
CMD ["mkdocs_simple_gen", "--serve", "--", "-a", "0.0.0.0:8000", "--dirtyreload"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

[![Test](https://github.com/athackst/mkdocs-simple-plugin/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/athackst/mkdocs-simple-plugin/actions/workflows/test.yml)
[![Docs](https://github.com/athackst/mkdocs-simple-plugin/actions/workflows/publish_docs.yml/badge.svg?branch=main)](https://github.com/athackst/mkdocs-simple-plugin/actions/workflows/publish_docs.yml)
[![Docker](https://img.shields.io/docker/pulls/althack/mkdocs-simple-plugin)](https://hub.docker.com/r/althack/mkdocs-simple-plugin)
[![pypi](https://img.shields.io/pypi/dm/mkdocs-simple-plugin?label=pypi%20downloads&color=blue)](https://pypi.org/project/mkdocs-simple-plugin/)
[![Docker](https://img.shields.io/docker/pulls/althack/mkdocs-simple-plugin)](https://hub.docker.com/r/althack/mkdocs-simple-plugin)
[![pypi](https://img.shields.io/pypi/dm/mkdocs-simple-plugin?label=pypi%20downloads&color=blue)](https://pypi.org/project/mkdocs-simple-plugin/)
[![Github Action](https://img.shields.io/badge/github%20action-download-blue)](https://github.com/marketplace/actions/mkdocs-simple-action)

# mkdocs-simple-plugin
Expand All @@ -16,7 +16,7 @@ You may be wondering why you would want to generate a static site for your proje

* **My repository is too big for a single documentation source.**

Sometimes it isn't feasible to consolidate all documentation within an upper level `docs` directory. In general, if your codebase is too large to fit well within a single `include` directory, your codebase is also too large for documentation in a single `docs` directory.
Sometimes it isn't feasible to consolidate all documentation within an upper level `docs` directory. In general, if your codebase is too large to fit well within a single `include` directory, your codebase is also too large for documentation in a single `docs` directory.

Since it's typically easier to keep documentation up to date when it lives as close to the code as possible, it is better to create multiple sources for documentation.

Expand Down
5 changes: 4 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
site_name: athackst/mkdocs-simple-plugin
docs_dir: /tmp/mkdocs-simple/mkdocs-simple-plugin
plugins:
- simple
- simple:
build_docs_dir: build/docs
ignore_folders:
- venv/*
- awesome-pages
- macros
- search
Expand Down
29 changes: 21 additions & 8 deletions mkdocs_simple_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import os
import shutil
import tempfile
import time
import yaml


Expand Down Expand Up @@ -256,6 +257,12 @@ def __init__(self):
"""Set up internal variables."""
self.orig_docs_dir = None
self.paths = None
self.local_config = {'last_build_time': None}
self.dirty = False

def on_startup(self, *, command, dirty: bool) -> None:
"""Performs one-time instrumentation of plugin on startup"""
self.dirty = dirty

def on_config(self, config, **kwargs):
"""Update configuration to use a temporary build directory."""
Expand All @@ -267,12 +274,17 @@ def on_config(self, config, **kwargs):
default_flow_style=False,
allow_unicode=True,
encoding=None)
self.local_config.update(self.config)

# Create a temporary build directory, and set some options to serve it
# PY2 returns a byte string by default. The Unicode prefix ensures a
# Unicode string is returned. And it makes MkDocs temp dirs easier to
# identify.
build_docs_dir = self.config['build_docs_dir']
build_docs_dir = self.local_config['build_docs_dir']
self.local_config['dirty'] = self.dirty and bool(build_docs_dir)
if self.local_config['dirty']:
utils.log.debug("mkdocs-simple-plugin: incremental mode engaged")

if not build_docs_dir:
build_docs_dir = tempfile.mkdtemp(
prefix="mkdocs_simple_" +
Expand All @@ -282,7 +294,7 @@ def on_config(self, config, **kwargs):
utils.log.info(
"mkdocs-simple-plugin: build_docs_dir: %s",
build_docs_dir)
self.config['build_docs_dir'] = build_docs_dir
self.local_config['build_docs_dir'] = build_docs_dir
# Clean out build folder on config
shutil.rmtree(build_docs_dir, ignore_errors=True)
os.makedirs(build_docs_dir, exist_ok=True)
Expand All @@ -291,26 +303,27 @@ def on_config(self, config, **kwargs):
# Update the docs_dir with our temporary one
config['docs_dir'] = build_docs_dir
# Add all markdown extensions to include list
self.config['include_extensions'] = list(utils.markdown_extensions) + \
self.config['include_extensions']
self.local_config['include_extensions'] = list(
utils.markdown_extensions) + self.local_config['include_extensions']

# Always ignore the output paths
self.config["ignore_paths"] = [
self.local_config["ignore_paths"] = [
get_config_site_dir(config.config_file_path),
config['site_dir'],
self.config['build_docs_dir']]
self.local_config['build_docs_dir']]
return config

def on_pre_build(self, *, config):
"""Build documentation directory with files according to settings."""
# Configure simple
simple = Simple(**self.config)
simple = Simple(**self.local_config)

# Merge docs
if self.config["merge_docs_dir"]:
if self.config["merge_docs_dir"] and not simple.is_incremental():
simple.merge_docs(self.orig_docs_dir)
# Copy all of the valid doc files into build_docs_dir
self.paths = simple.build_docs()
self.local_config['last_build_time'] = time.time()

def on_serve(self, server, *, config, builder):
"""Add files to watch server."""
Expand Down
18 changes: 18 additions & 0 deletions mkdocs_simple_plugin/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import stat
import sys
import pathlib
import traceback

from mkdocs import utils
from mkdocs_simple_plugin.semiliterate import Semiliterate
Expand All @@ -24,6 +25,8 @@ def __init__(
ignore_hidden: bool,
ignore_paths: list,
semiliterate: dict,
dirty: bool,
last_build_time: float,
**kwargs):
"""Initialize module instance with settings.

Expand All @@ -37,6 +40,9 @@ def __init__(
ignore_paths (list): Absolute filepaths to exclude
semiliterate (dict): Settings for processing file content in
Semiliterate
dirty (bool): Whether the server is running in dirty mode
last_build_time (float): For dirty builds, the time at which the
previous build was run

"""
self.build_dir = build_docs_dir
Expand All @@ -47,6 +53,8 @@ def __init__(
self.hidden_prefix = set([".", "__"])
self.ignore_paths = set(ignore_paths)
self.semiliterate = []
self.dirty = dirty
self.last_build_time = last_build_time
for item in semiliterate:
self.semiliterate.append(Semiliterate(**item))

Expand Down Expand Up @@ -141,6 +149,10 @@ def hidden_prefix(name):

return extract

def is_incremental(self) -> bool:
"""Whether the plugin is currently running in incremental mode"""
return self.dirty and self.last_build_time is not None

def merge_docs(self, from_dir):
"""Merge docs directory"""
# Copy contents of docs directory if merging
Expand All @@ -166,6 +178,8 @@ def copy_directory(from_dir: str, to_dir: str):
utils.log.debug(
"mkdocs-simple-plugin: %s/* --> %s/*",
source_file, destination_file)
if self.is_incremental():
return

if os.path.exists(from_dir):
copy_directory(from_dir, self.build_dir)
Expand All @@ -178,6 +192,10 @@ def build_docs(self) -> list:
for file in files:
if not os.path.isfile(file):
continue
if self.is_incremental() and (
os.path.getmtime(file) < self.last_build_time):
continue

from_dir = os.path.dirname(file)
name = os.path.basename(file)
build_prefix = os.path.normpath(
Expand Down