Skip to content

Commit

Permalink
Better jinja (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
WaylonWalker authored Jun 8, 2024
1 parent 29f92fb commit 5a4a0a5
Show file tree
Hide file tree
Showing 88 changed files with 3,690 additions and 400 deletions.
148 changes: 146 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ upgrading.

#### Feeds are now a list

Feeds are now a list of Objects within the configuration that you choose from
whether its toml or yaml. Also templates_dir is now configurable, and once you
have a templates dir it is better to specify templates by name relative to your
templates_dir.

```toml
[markata]
templates_dir = "pages/templates"

[markata.feeds.published]
template="pages/templates/archive_template.html"
card_template = "pages/templates/feed_card.html"
template="archive_template.html"
card_template = "feed_card.html"
filter="date<=today and templateKey in ['blog-post', 'til'] and status.lower()=='published'"
sort="date"
```
Expand Down Expand Up @@ -64,6 +72,142 @@ filter="published == 'False'"
color='red'
```

### Better Jinja Templates

Markata now fully supports jinja templates with a loader that will load from
your templates directory, the markata built-in templates, and from a
dynamically generated templates directory in your .markata.cache directory.

#### cli

You can list out your templates and configuration with the following command

``` bash
markata templates show
```

#### Variables

The following variables are available within jinja templates for post
templates.

- `__version__` - the version of markata
- `markata` - the markata instance
- `config` - the markata config
- `body` - the body of the post
- `post` - the current post object

Similarly from within rendering feeds.

- `__version__` - the version of markata
- `markata` - the markata instance
- `config` - the markata config
- `posts` - the list of posts
- `feed` - the current feed object

#### Feeds cli

The feeds cli will help show which templates each feed will be using.

``` bash
❯ markata feeds show
Feeds 6
┏━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Feed ┃ posts ┃ config ┃
┡━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ project_gallery │ 2 │ DEFAULT_TITLE: All Posts │
│ │ │ title: Project Gallery │
│ │ │ slug: project-gallery │
│ │ │ name: project_gallery │
│ │ │ filter: 'project-gallery' in str(path) │
│ │ │ sort: title │
│ │ │ reverse: False │
│ │ │ rss: True │
│ │ │ sitemap: True │
│ │ │ card_template: card.html │
│ │ │ template: feed.html │
│ │ │ rss_template: rss.xml │
│ │ │ sitemap_template: sitemap.xml │
│ │ │ xsl_template: rss.xsl │
│ │ │ │
│ docs │ 10 │ DEFAULT_TITLE: All Posts │
│ │ │ title: Documentation │
│ │ │ slug: docs │
│ │ │ name: docs │
│ │ │ filter: "markata" not in slug and "tests" not in slug and ... │
│ │ │ sort: slug │
│ │ │ reverse: False │
│ │ │ rss: True │
│ │ │ sitemap: True │
│ │ │ card_template: card.html │
│ │ │ template: feed.html │
│ │ │ rss_template: rss.xml │
│ │ │ sitemap_template: sitemap.xml │
│ │ │ xsl_template: rss.xsl │
│ │ │ │
│ autodoc │ 17 │ DEFAULT_TITLE: All Posts │
│ │ │ title: AutoDoc Python Modules. │
│ │ │ slug: autodoc │
│ │ │ name: autodoc │
│ │ │ filter: "markata" in slug and "plugin" not in slug and "te... │
│ │ │ sort: slug │
│ │ │ reverse: False │
│ │ │ rss: True │
│ │ │ sitemap: True │
│ │ │ card_template: card.html │
│ │ │ template: feed.html │
│ │ │ rss_template: rss.xml │
│ │ │ sitemap_template: sitemap.xml │
│ │ │ xsl_template: rss.xsl │
│ │ │ │
│ all │ 73 │ DEFAULT_TITLE: All Posts │
│ │ │ title: All Markata Modules │
│ │ │ slug: all │
│ │ │ name: all │
│ │ │ filter: True │
│ │ │ sort: date │
│ │ │ reverse: False │
│ │ │ rss: True │
│ │ │ sitemap: True │
│ │ │ card_template: card.html │
│ │ │ template: feed.html │
│ │ │ rss_template: rss.xml │
│ │ │ sitemap_template: sitemap.xml │
│ │ │ xsl_template: rss.xsl │
│ │ │ │
│ core_modules │ 17 │ DEFAULT_TITLE: All Posts │
│ │ │ title: Markata Core Modules │
│ │ │ slug: core_modules │
│ │ │ name: core_modules │
│ │ │ filter: 'plugin' not in slug and 'test' not in slug and ti... │
│ │ │ sort: date │
│ │ │ reverse: False │
│ │ │ rss: True │
│ │ │ sitemap: True │
│ │ │ card_template: card.html │
│ │ │ template: feed.html │
│ │ │ rss_template: rss.xml │
│ │ │ sitemap_template: sitemap.xml │
│ │ │ xsl_template: rss.xsl │
│ │ │ │
│ plugins │ 42 │ DEFAULT_TITLE: All Posts │
│ │ │ title: Markata Plugins │
│ │ │ slug: plugins │
│ │ │ name: plugins │
│ │ │ filter: 'plugin' in slug and 'test' not in slug │
│ │ │ sort: date │
│ │ │ reverse: False │
│ │ │ rss: True │
│ │ │ sitemap: True │
│ │ │ card_template: card.html │
│ │ │ template: feed.html │
│ │ │ rss_template: rss.xml │
│ │ │ sitemap_template: sitemap.xml │
│ │ │ xsl_template: rss.xsl │
│ │ │ │
└─────────────────┴───────┴───────────────────────────────────────────────────────────────┘
```
## 0.7.4
- Fix: Icon resize broken from PIL 10.0.0 release
Expand Down
33 changes: 6 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,10 @@ allow to build your site right out of the box with nothing more than Markdown.

```bash
python -m pip install markata
```

### Create Some Content

Make some `.md` files in your current working directory. By default, `markata`
will recursively look in all subdirectories for markdown files `**/*.md`.

```bash
mkdir pages
echo '# My First Post' > first-post.md
echo '# Hello World' > hello-world.md
```

> This example shows how you can build a site from only a single markdown
> file.
### Build your site

Install markata into your virtual environment and run `markata build`. It will
create your site in `./markout`, leave its cache in `./.markata.cache`, and
copy all assets from `./static` into `./markout` by default.

```bash
python -m pip install markata
markata build

# or if pipx is your thing
pipx run markata build

pipx install markata
```

### Building a Blog with Markata _using a template_
Expand All @@ -75,14 +51,17 @@ to fill in the jinja variables in this repo.
```bash
markata new blog [directory]

markata build
# start the site and watch for changes
hatch run tui
markata serve
```

Now if you open localhost:8000, you will be presented with an example site that
will walk you through some features of markata. You can play with it at
your own pace, or drop all the pages and start writing your own content.

![new blog gif](./static/new-blog.gif)

## Motivation

Markata is able to build your site purely from Markdown, allowing you to get
Expand Down
48 changes: 48 additions & 0 deletions docs/create-manual.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Manually create a new site
description: Lets manually create a new website with markata.

---

Markata has some templates that let you get up and running quickly, but you
_can_ make a site with only markdown if you wanted.

### Installation

`markata` is hosted on pypi and can be installed using pip.

```bash
python -m pip install markata

# or if pipx is your thing

pipx install markata
```

### Create Some Content

Make some `.md` files in your current working directory. By default, `markata`
will recursively look in all subdirectories for markdown files `**/*.md`.

```bash
mkdir pages
echo '# My First Post' > first-post.md
echo '# Hello World' > hello-world.md
```

> This example shows how you can build a site from only a single markdown
> file.
### Build your site

Install markata into your virtual environment and run `markata build`. It will
create your site in `./markout`, leave its cache in `./.markata.cache`, and
copy all assets from `./static` into `./markout` by default.

```bash
python -m pip install markata
markata build

# or if pipx is your thing
pipx run markata build
```
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ date and includes a lot of examples of how to use the markata cli.

> **Yes** this library generates it's own docs
- [All Modules](https://markata.dev/autodoc/)
- [Core Modules](https://markata.dev/core_modules/)
- [Plugins](https://markata.dev/plugins/)
- [color theme](https://markata.dev/color-theme/)
- [All Modules](/autodoc/)
- [Core Modules](/core_modules/)
- [Plugins](/plugins/)
- [color theme](/color-theme/)
5 changes: 2 additions & 3 deletions docs/project-gallery/markata_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ url: https://markata.dev/

---

[![Markta.dev home page](/markata.dev_.webp)](https://markata.dev)
[![Markta.dev home page](/markata.dev_.webp)](https://markata.dev){.shadow-2xl}

Markata builds it's own docs in completely in `markata` using all built in
templatates and plugins.


[![Markta.dev home page](/markata.dev_markata_plugins_base-cli_.webp)](https://https://markata.dev/markata/plugins/base-cli/)
[![Markta.dev home page](/markata.dev_markata_plugins_base-cli_.webp)](https://https://markata.dev/markata/plugins/base-cli/){.shadow-2xl}

Using the `markata.plugins.docs` plugin it is able to load all the python
files. It renders out all the docstrings as markdown and shows the code in
Expand Down
58 changes: 58 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

record-tapes:
#!/usr/bin/env bash
set -euxo pipefail
# Export the function to be used by parallel
convert_tape() {
tape_file="$1"
base_name=$(basename "$tape_file" .tape)
vhs "tapes/$base_name.tape" -o "static/$base_name.gif"
}
export -f convert_tape
# Find all .tape files and run the convert_tape function in parallel
find tapes -name '*.tape' | parallel convert_tape


cov:
#!/usr/bin/env bash
set -euxo pipefail
pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=markata --cov=tests tests

no-cov:
#!/usr/bin/env bash
set -euxo pipefail
pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=markata --cov=tests tests --no-cov
lint:
#!/usr/bin/env bash
set -euxo pipefail
ruff check markata
format:
#!/usr/bin/env bash
set -euxo pipefail
ruff format .
build-docs:
#!/usr/bin/env bash
set -euxo pipefail
markata build
serve:
#!/usr/bin/env bash
set -euxo pipefail
python -m http.server --bind 0.0.0.0 8000 --directory markout
ruff-fix:
#!/usr/bin/env bash
set -euxo pipefail
ruff check markata --fix
lint-format: lint format

lint-test: lint format cov



Loading

0 comments on commit 5a4a0a5

Please sign in to comment.