Add README and requirements

This commit is contained in:
ge 2022-08-07 13:53:21 +03:00
parent 9a9405cb82
commit bd5d5f7273
4 changed files with 126 additions and 108 deletions

1
.gitignore vendored
View File

@ -2,4 +2,3 @@ build/
assets/
content/
layouts/
*.txt

122
README.md Normal file
View File

@ -0,0 +1,122 @@
Static site generator from reStructuredText files.
# Usage
Run:
```shell
git clone https://git.nxhs.cloud/ge/blog.git && cd blog
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
mkdir -p {layouts,content,assets/css/pygments}
touch settings.toml content/my_page.rst layouts/{base,index,post}.j2
make css default
```
Put in **settings.toml**:
```toml
[site]
title = 'My site'
index_page_title = 'Home page'
datetime_format = '%d %b %Y'
[build]
build_dir = 'build'
content_dir = 'content'
templates_dir = 'layouts'
assets_dir = 'assets'
[pygments]
theme = 'default'
[docutils]
```
Create basic Jinja2 templates.
**layouts/base.j2**:
```jinja2
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="assets/css/pygments/{{ pygments_theme }}.css">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<header>
<p>
{% if posts %}
{{ site_title }}
{% else %}
<a href="/">{{ site_title }}</a> / {{ page_title }}</p>
{% endif %}
</p>
</header>
<main>
{% block content %}{% endblock %}
</main>
<footer>
</footer>
</body>
</html>
```
**layouts/index.j2**:
```jinja2
{% extends "base.j2" %}
{% block content %}
<section>
<ul id="posts">
{% for post in posts %}
<li>
<a href="/{{ post['path'] }}">{{post['title'] }}</a>
<span class="meta"> — {{ post['date'] }}</span>
</li>
{% endfor %}
</ul>
</section>
{% endblock %}
```
**layouts/post.j2**:
```jinja2
{% extends "base.j2" %}
{% block content %}
<article>
{{ post | safe }}
<article>
{% endblock %}
```
Put in **content/my_page.rst**:
```restructuredtext
:title: My first page
:date: 01 Jan 1970
=============
My first page
=============
Hello, World!
```
Build site:
```
make
```
See HTML in build/ dir. Write your own CSS styles.

View File

@ -1,107 +0,0 @@
Static site generator from reStructuredText files.
Usage
=====
Run::
git clone ttps://git.nxhs.cloud/ge/blog.git && cd blog
python3 -m venv env
source env/bin/activate
pip intall -r requirements.txt
mkdir -p {layouts,content,assets/css/pygments}
touch settings.toml content/my_page.rst layout/{base,index,post}.j2
make css default
Put in settings.toml::
[site]
title = 'My site'
index_page_title = 'Home page'
datetime_format = '%d %b %Y'
[build]
build_dir = 'build'
content_dir = 'content'
templates_dir = 'layouts'
assets_dir = 'assets'
[pygments]
theme = 'default'
Create basic Jinja2 templates.
base.j2::
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="assets/css/pygments/{{ pygments_theme }}.css">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<header>
<p>
{% if posts %}
{{ site_title }}
{% else %}
<a href="/">{{ site_title }}</a> / {{ page_title }}</p>
{% endif %}
</p>
</header>
<main>
{% block content %}{% endblock %}
</main>
<footer>
</footer>
</body>
</html>
index.j2::
{% extends "base.j2" %}
{% block content %}
<section>
<ul id="posts">
{% for post in posts %}
<li>
<a href="/{{ post['path'] }}">{{post['title'] }}</a>
<span class="meta"> — {{ post['date'] }}</span>
</li>
{% endfor %}
</ul>
</section>
{% endblock %}
post.j2::
{% extends "base.j2" %}
{% block content %}
<article>
{{ post | safe }}
<article>
{% endblock %}
Put in content/my_page.rst::
:title: My first page
:date: 01 Jan 1970
=============
My first page
=============
Hello, World!
Build site::
make
See HTML in build/ dir. Write your own CSS styles.

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
docutils==0.17.1
Jinja2==3.1.2
Pygments==2.12.0
toml==0.10.2