Skip to content
Merged
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
@@ -1,6 +1,7 @@
*~
\#*\#
.\#*
examples/*/*/public

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
17 changes: 17 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Examples

This directory contains runnable `httk-web` examples.

- `modern/`: recommended v2-first examples (Jinja2 templates, modern metadata).
- `legacy/`: compatibility-mode examples that use deprecated legacy syntax/features.

Modern includes:
- `minimal/`
- `rst_site/` (modern replacement for `rst_templator`)
- `blog/` (modern replacement for legacy blog example)
- `search_app/` (modern replacement for legacy search example)

Legacy now includes migrated variants of the original `6_website` examples,
including blog/search-style examples.

Legacy examples are kept to validate migration behavior and should not be used as the default style for new projects.
14 changes: 14 additions & 0 deletions examples/legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Legacy Examples

These examples intentionally use deprecated legacy features and require compatibility mode.

- `static_simple/`
- `hello_world_app/`
- `rst_templator/`
- `blog/`
- `search_app/`

Use the provided `serve_legacy_*.py` and `publish_legacy_*.py` scripts.

`search_app/` is included as a migrated legacy example, but it depends on legacy
`httk` database modules that are not part of `httk-web`.
6 changes: 6 additions & 0 deletions examples/legacy/blog/publish_legacy_blog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pathlib import Path

from httk.web import publish

ROOT = Path(__file__).parent
publish(ROOT / "src", ROOT / "public", "http://127.0.0.1/", compatibility_mode=True)
6 changes: 6 additions & 0 deletions examples/legacy/blog/serve_legacy_blog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pathlib import Path

from httk.web import serve

ROOT = Path(__file__).parent
serve(ROOT / "src", port=8080, compatibility_mode=True, config_name="config_dynamic")
4 changes: 4 additions & 0 deletions examples/legacy/blog/src/config.httkweb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
maintitle: My formidable website
menuitems-list: index, blog, contact
---
5 changes: 5 additions & 0 deletions examples/legacy/blog/src/config_dynamic.httkweb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
maintitle: My formidable website
menuitems-list: index, blog, contact
urls_without_ext: true
---
6 changes: 6 additions & 0 deletions examples/legacy/blog/src/content/404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
Title: My Website - Missing page
Name: "404"
Template: "404"
---
The page could not be found.
12 changes: 12 additions & 0 deletions examples/legacy/blog/src/content/blog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--------
Title: My Website - Blog posts
Name: Blog
Template: blog
Base_template: base_default
--------

Blog
====

Below is a list of all blog posts available here.

13 changes: 13 additions & 0 deletions examples/legacy/blog/src/content/blogposts/another_post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--------
Title: My Website - Another post
Author: Rickard Armiento
Date: 2023-10-04
Name: Another post
Template: blogpost
Base_template: base_default
--------

Another post
============

This is another post
13 changes: 13 additions & 0 deletions examples/legacy/blog/src/content/blogposts/hello-everyone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--------
Title: My Website - Hello Everyone
Author: Rickard Armiento
Date: 2023-10-03
Name: Hello Everyone
Template: blogpost
Base_template: base_default
--------

Hello everyone
==============

Hello everyone, this is the first blog post.
13 changes: 13 additions & 0 deletions examples/legacy/blog/src/content/blogposts/third_post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--------
Title: My Website - Third post
Author: Rickard Armiento
Date: 2023-10-05
Name: Third post
Template: blogpost
Base_template: base_default
--------

Third post
==========

This is the third post
12 changes: 12 additions & 0 deletions examples/legacy/blog/src/content/contact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-------
Title: My Website - Contact
Name: Contact
Template: default
Base_template: base_default
------

Contact
=======

Contact me here: someone@example.com

33 changes: 33 additions & 0 deletions examples/legacy/blog/src/content/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-----------
Title: My Website
Name: Main
Date: 2023-09-27
Version: 1
Author: Rickard Armiento
Template: default
Base_template: base_default
-----------

My website
==========

This is my formidable website. It contains the following sections:

* [Blog](blog)
* [Contact](contact)

Subheading
----------

Here is some nice math:

\(\int (x+y) dx\)

And a code segment:

``` python
x = 1
if x == 1:
# indented four spaces
print("x is 1.")
```
39 changes: 39 additions & 0 deletions examples/legacy/blog/src/functions/init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import datetime
import os
from pathlib import Path


def execute(global_data, **kargs):
prefix = Path(__file__).resolve().parents[1] / "content"
filterlist = [".md", ".rst", ".html"]
path = "blogposts"

# Chicken-or-egg problem of having to partially render blog posts to sort them, but their renders refer to the other blogposts
global_data['blogposts'] = []
global_data['blogposts_latest'] = []

def listdirsorted(path):
return [
x[0]
for x in sorted(
[
(
fn,
datetime.datetime.strptime(
str(global_data['pages'](os.path.join(path, fn), 'date')), "%Y-%m-%d"
),
)
for fn in os.listdir(prefix / path)
],
key=lambda x: x[1],
reverse=True,
)
]

global_data['blogposts'] = [
os.path.join(path, f)
for f in listdirsorted(path)
if os.path.isfile(prefix / path / f) and any([f.endswith(t) for t in filterlist])
]

global_data['blogposts_latest'] = global_data['blogposts'][:5]
Binary file added examples/legacy/blog/src/static/favicon.ico
Binary file not shown.
File renamed without changes.
104 changes: 104 additions & 0 deletions examples/legacy/blog/src/static/js/paginate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Based on https://stackoverflow.com/a/72308579 by rootShiv

function setup_pagination(table) {
var filter = $("#filter").val().toLowerCase();
var lastPage = 1;
$("#maxRows").on("change", function (evt) {
lastPage = 1;
$(".pagination").find("li").slice(1, -1).remove();
var trnum = 0;
var maxRows = parseInt($(this).val());
$(table + " tr").each(function (el) {
a = $(this);
txtValue = a.text().toLowerCase();
if (!filter || txtValue.indexOf(filter) > -1) {
trnum++;
}
});
var pagenum = Math.ceil(trnum / maxRows);
for (var i = 1; i <= pagenum; i++) {
$(".pagination #insert-pages-here")
.before(
'<li class="page-item" data-page="'+i+'"><a class="page-link" href="#">'+(i)+
'<span class="sr-only">(current)</span></a></li>')
.show();
}
$('.pagination [data-page="1"]').addClass("active");
$(".pagination li").on("click", function (evt) {
evt.stopImmediatePropagation();
evt.preventDefault();
var pageNum = $(this).attr("data-page");
activate_page(pageNum, table, filter);
});
pagination_limits();
}).val(10).change();
activate_page(1, table, filter);
}

function activate_page(pageNum, table, filter) {
var maxRows = parseInt($("#maxRows").val());
if (pageNum == "prev") {
if (lastPage == 1) {
return;
}
pageNum = --lastPage;
}
if (pageNum == "next") {
if (lastPage == $(".pagination li").length - 2) {
return;
}
pageNum = ++lastPage;
}
lastPage = pageNum;
var trIndex = 0;
$(".pagination li").removeClass("active");
$('.pagination [data-page="' + lastPage + '"]').addClass("active");
pagination_limits();
$(table + " tr").each(function () {

a = $(this);
txtValue = a.text().toLowerCase();
if (!filter || txtValue.indexOf(filter) > -1) {
trIndex++;
if (trIndex > maxRows * pageNum || trIndex <= maxRows * pageNum - maxRows) {
$(this).hide();
} else {
$(this).show();
}
} else {
$(this).hide();
}
});
}

function pagination_limits() {
if ($(".pagination li").length > 7) {
if ($(".pagination li.active").attr("data-page") <= 3) {
$(".pagination li:gt(5)").hide();
$(".pagination li:lt(5)").show();
$('.pagination [data-page="next"]').show();
}
if ($(".pagination li.active").attr("data-page") > 3) {
$(".pagination li:gt(0)").hide();
$('.pagination [data-page="next"]').show();
for (
let i = parseInt($(".pagination li.active").attr("data-page")) - 2;
i <= parseInt($(".pagination li.active").attr("data-page")) + 2;
i++
) {
$('.pagination [data-page="' + i + '"]').show();
}
}
}
}

$('#filterform').on('reset', function(e)
{
setTimeout(function() { setup_pagination("#table-id"); });
});

$('#filterform').on('submit',function(event) {
event.preventDefault();
});

setup_pagination("#table-id");
Loading
Loading