Skip to content

Commit

Permalink
Remove table of contents generator
Browse files Browse the repository at this point in the history
  • Loading branch information
iizukak committed Jan 30, 2023
1 parent 5c80fd1 commit 81c9579
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 108 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ $ make demoserver

## Documentation Guide

- Converted `index.html` includes the automatically generated table of contents.
- Each MarkDown file's first `#` in will be the page title. We need at least one `#` in a doc.
- mdsite copies `static` directory to the output directory.

### Syntax highlighting
Expand Down
17 changes: 2 additions & 15 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<header>
<a href="./index.html">The demo site of mdsite</a>
</header>
<h1>mdsite</h1>
<h1>mdsite</h1>
<p><a href="https://github.com/iizukak/mdsite/actions/workflows/test.yaml"><img alt="example workflow" src="https://github.com/iizukak/mdsite/actions/workflows/test.yaml/badge.svg" /></a></p>
<p>mdsite is a command line tool that generates a static site from Markdown files.</p>
<p><a href="https://iizukak.github.io/mdsite/">demo</a>,
Expand Down Expand Up @@ -79,8 +79,6 @@ <h2>Development</h2>

<h2>Documentation Guide</h2>
<ul>
<li>Converted <code>index.html</code> includes the automatically generated table of contents.</li>
<li>Each MarkDown file's first <code>#</code> in will be the page title. We need at least one <code>#</code> in a doc.</li>
<li>mdsite copies <code>static</code> directory to the output directory.</li>
</ul>
<h3>Syntax highlighting</h3>
Expand Down Expand Up @@ -128,19 +126,8 @@ <h2>FAQ</h2>
</ul>
<h2>License</h2>
<p><a href="https://spdx.org/licenses/Apache-2.0.html">Apache License 2.0</a></p>

<h2>Table of contents</h2>
<ul>



<li><a href="index.html">mdsite
</a></li>

</ul>

<footer>
<p>created at: 2022/11/01, updated at: 2023/01/25</p>
<p>created at: 2022/11/01, updated at: 2023/01/30</p>
<p>IIZUKA Kentaro © 2023</p>
</footer>
</body>
Expand Down
49 changes: 7 additions & 42 deletions mdsite/mdsite.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,12 @@ def parse_config(config_file_name: str) -> dict:

def load_template() -> tuple[str, str, str]:
# Load jinja2 template files.
# index.html is a main page template of the site.
# pages.html is a general page template.
pkg = importlib.resources.files("mdsite")
index_template_path = pkg / "template" / "index.html"
page_template_path = pkg / "template" / "pages.html"
template_path = pkg / "template" / "template.html"
css_path = pkg / "template" / css_file_name
index_template = index_template_path.read_text()
page_template = page_template_path.read_text()
template = template_path.read_text()
css = css_path.read_text()
return index_template, page_template, css
return template, css


def calc_link_to_root(path: Path) -> str:
Expand Down Expand Up @@ -162,32 +158,6 @@ def make_time_str(timestamp: str, config: dict) -> str:
return d.strftime(config["date_format"])


def convert_index(
markdown_file: MarkDownFile,
config: dict,
template: str,
markdown_files: list[MarkDownFile],
):
# Convert index.md's MarkDown instance to index.html.
markdown_html = markdown(
markdown_file.contents, extensions=["fenced_code", "codehilite", "mdx_math"]
)
created_at = make_time_str(markdown_file.created_at, config)
updated_at = make_time_str(markdown_file.edited_at, config)
year = date.today().year
template = Template(source=template)
converted_html = template.render(
contents=markdown_html,
config=config,
created_at=created_at,
updated_at=updated_at,
year=year,
markdowns=markdown_files,
)
with open(markdown_file.output_path, "w") as f:
f.write(converted_html)


def convert_page(markdown_file: MarkDownFile, config: dict, template: str):
# Convert a MarkDown instance into .html.
markdown_html = markdown(
Expand All @@ -209,14 +179,9 @@ def convert_page(markdown_file: MarkDownFile, config: dict, template: str):
f.write(converted_html)


def convert(
markdown_files: list[MarkDownFile], config: dict, templates: tuple[str, str]
):
def convert(markdown_files: list[MarkDownFile], config: dict, templates: str):
for markdown_file in markdown_files:
if markdown_file.output_path == Path(config["output_dir"], "index.html"):
convert_index(markdown_file, config, templates[0], markdown_files)
else:
convert_page(markdown_file, config, templates[1])
convert_page(markdown_file, config, templates)


def write_css(css: str, config: dict):
Expand All @@ -234,10 +199,10 @@ def write_static(config: dict):

def main(config_file_name: str):
config = parse_config(config_file_name)
index_template, page_template, css = load_template()
template, css = load_template()
markdown_files = load_markdown_files(config)
make_output_dirs(markdown_files)
convert(markdown_files, config, (index_template, page_template))
convert(markdown_files, config, (template))
write_css(css, config)
write_static(config)

Expand Down
48 changes: 0 additions & 48 deletions mdsite/template/index.html

This file was deleted.

File renamed without changes.
6 changes: 5 additions & 1 deletion tests/in/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ $$
\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
{1+\frac{e^{-8\pi}} {1+\ldots} } } }
$$
$$

## Link to sub directory

[link to dir/subdir.html](./dir/subdir.html)

0 comments on commit 81c9579

Please sign in to comment.