Compare commits

...

3 Commits

Author SHA1 Message Date
Ryan Rix f942906fd8 make the flake use my forked nixpkgs sorry 🫡 2024-02-26 18:05:06 -08:00
Ryan Rix 42c451320b add tags to the page sidebar 2024-02-26 18:04:58 -08:00
Ryan Rix 9840007a1b flesh out the tag pages more 2024-02-26 17:42:21 -08:00
13 changed files with 178 additions and 67 deletions

View File

@ -171,6 +171,13 @@ class Page(EMOM('page'), models.Model):
def collect_keywords(self):
return self.file.keyword_set
def collect_tags(self):
return [
tag
for heading in self.file.heading_set.all()
for tag in heading.tag_set.all()
]
def collect_references(self):
return [
reference
@ -646,10 +653,15 @@ def render_page(request, site, full_key):
backlinks=the_page.collect_backlinks(),
keywords=the_page.collect_keywords().all(),
references=the_page.collect_references(),
tags=the_page.collect_tags(),
))
#+end_src
*** Rendering the converted Org HTML in to a whole web-page
:PROPERTIES:
:ID: 20240226T174503.655394
:ROAM_ALIASES: "Arcology Page HTML Template"
:END:
The =page= template extends the app template defined below, which provides four blocks to inject content in to:
@ -697,12 +709,23 @@ The main =content= block contains the =<main>= generated by the native parser, a
</div>
{% endif %}
{% if tags|length > 0 %}
<div class="tags">
<h3>Page Tags</h3>
<ul class="tags">
{% for tag in tags %}
<li><a href="/tags/{{ tag.tag }}">{{tag.tag}}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if references|length > 0 %}
<div class="references">
<h3>External References</h3>
<ul class="references">
{% for ref in references %}
<li><a href="{{ ref.ref }}">{{ref.ref}}</a></li>
<li><a target="_blank" href="{{ ref.ref }}">{{ref.ref}}</a></li>
{% endfor %}
</ul>
</div>
@ -755,6 +778,10 @@ Here's a really simple 404 template, too.
#+end_src
*** Org Page-specific CSS Stylings
:PROPERTIES:
:ID: 20240226T174517.235275
:ROAM_ALIASES: "Arcology Page CSS Files"
:END:
Most of the page CSS is defined below, but the content CSS is here, nearer the actual implementation of the flexbox:
@ -839,7 +866,7 @@ These rules annotate task headings by inserting an icon before them.
}
#+end_src
** INPROGRESS Atom Feed Handler
** Atom Feed Handler
:PROPERTIES:
:ID: 20240204T234814.612917
:END:
@ -939,7 +966,10 @@ def get_item(dictionary, key):
return dictionary.get(key)
#+end_src
*** NEXT [#A] see if the IDs are consistent with the old generator
*** CANCELLED [#A] see if the IDs are consistent with the old generator
:LOGBOOK:
- State "CANCELLED" from "NEXT" [2024-02-26 Mon 17:46]
:END:
** NEXT unpublished/not found endpoint
@ -1055,7 +1085,6 @@ The base template provides some basic information and loads the CSS sheets neces
<meta name="generator" content="Arcology Site Engine https://engine.arcology.garden/"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}{{head_title | default:"The Arcology Project" }}{% endblock %}</title>
<script src="{% static 'sitemap/js/htmx.js' %}" defer></script>
{% block extra_head %}{% endblock %}
</head>
#+end_src

View File

@ -100,6 +100,13 @@ class Page(EMOM('page'), models.Model):
def collect_keywords(self):
return self.file.keyword_set
def collect_tags(self):
return [
tag
for heading in self.file.heading_set.all()
for tag in heading.tag_set.all()
]
def collect_references(self):
return [
reference

View File

@ -18,7 +18,6 @@
<meta name="generator" content="Arcology Site Engine https://engine.arcology.garden/"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}{{head_title | default:"The Arcology Project" }}{% endblock %}</title>
<script src="{% static 'sitemap/js/htmx.js' %}" defer></script>
{% block extra_head %}{% endblock %}
</head>
{# Arcology Site Templates:2 ends here #}

View File

@ -36,12 +36,23 @@
</div>
{% endif %}
{% if tags|length > 0 %}
<div class="tags">
<h3>Page Tags</h3>
<ul class="tags">
{% for tag in tags %}
<li><a href="/tags/{{ tag.tag }}">{{tag.tag}}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if references|length > 0 %}
<div class="references">
<h3>External References</h3>
<ul class="references">
{% for ref in references %}
<li><a href="{{ ref.ref }}">{{ref.ref}}</a></li>
<li><a target="_blank" href="{{ ref.ref }}">{{ref.ref}}</a></li>
{% endfor %}
</ul>
</div>

View File

@ -73,6 +73,7 @@ def render_page(request, site, full_key):
backlinks=the_page.collect_backlinks(),
keywords=the_page.collect_keywords().all(),
references=the_page.collect_references(),
tags=the_page.collect_tags(),
))
# Arcology Org Page handler:2 ends here

View File

@ -6,11 +6,11 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1708237433,
"narHash": "sha256-YDvf7g7JUwpFr+SVyKONoiqnSrcfooQy38xAye19U9I=",
"lastModified": 1708999083,
"narHash": "sha256-BEbba8BkuA5GA8LOhXT6kSX+q9hbdp137lTEgb7iaP8=",
"ref": "refs/heads/main",
"rev": "9700b20d0e3afb15f5605332197988805eec0cf7",
"revCount": 159,
"rev": "1c8c06702e1ad6145bed80f9ad9c3ec4b7073eda",
"revCount": 160,
"type": "git",
"url": "https://code.rix.si/rrix/arroyo"
},
@ -24,11 +24,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
@ -57,16 +57,18 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1698553279,
"narHash": "sha256-T/9P8yBSLcqo/v+FTOBK+0rjzjPMctVymZydbvR/Fak=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "90e85bc7c1a6fc0760a94ace129d3a1c61c3d035",
"type": "github"
"lastModified": 1708988343,
"narHash": "sha256-cdBpU7K65DOx+jtqxNDL1hYea4KfpWAgBgp2Rb39zcw=",
"ref": "nixos-23.11",
"rev": "0c3e150b06447d68ff3363f8a433b34fa4872660",
"revCount": 556130,
"type": "git",
"url": "ssh://gitea@last-bank:2222/rrix/nixpkgs"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
"ref": "nixos-23.11",
"type": "git",
"url": "ssh://gitea@last-bank:2222/rrix/nixpkgs"
}
},
"root": {

View File

@ -21,7 +21,7 @@ at the top here, describe the class layout and the overall usage of this module.
#+BEGIN_SRC python :tangle roam/models.py
from __future__ import annotations
import hashlib
from typing import List
from typing import List, Set
from django.db import models
from django.conf import settings
@ -419,16 +419,23 @@ class Tag(EMOM('tag'), models.Model):
)
tag = models.CharField(max_length=256)
def pages(self) -> List['Page']:
return self.__class__.pages_by_name(self.tag)
def related_pages(self) -> Set['arcology.models.Page']:
return set(self.__class__.pages_by_name(self.tag))
@classmethod
def pages_by_name(cls, tag_name: str) -> List['Page']:
import arcology.models
return set([
arcology.models.Page.objects.get(file=tag_obj.heading.path_id)
def weighted_pages_by_name(cls, tag_name):
pages = cls.pages_by_name(tag_name)
ret = dict()
for page in pages:
ret[page] = ret.get(page, 0) + 1
return ret
@classmethod
def pages_by_name(cls, tag_name: str) -> List['arcology.models.Page']:
return [
tag_obj.heading.path.page_set.first()
for tag_obj in cls.objects.filter(tag=tag_name).distinct()
])
]
@classmethod

View File

@ -1,7 +1,7 @@
# [[file:../roam.org::*Org-Roam Caching Models][Org-Roam Caching Models:1]]
from __future__ import annotations
import hashlib
from typing import List
from typing import List, Set
from django.db import models
from django.conf import settings
@ -157,16 +157,23 @@ class Tag(EMOM('tag'), models.Model):
)
tag = models.CharField(max_length=256)
def pages(self) -> List['Page']:
return self.__class__.pages_by_name(self.tag)
def related_pages(self) -> Set['arcology.models.Page']:
return set(self.__class__.pages_by_name(self.tag))
@classmethod
def pages_by_name(cls, tag_name: str) -> List['Page']:
import arcology.models
return set([
arcology.models.Page.objects.get(file=tag_obj.heading.path_id)
def weighted_pages_by_name(cls, tag_name):
pages = cls.pages_by_name(tag_name)
ret = dict()
for page in pages:
ret[page] = ret.get(page, 0) + 1
return ret
@classmethod
def pages_by_name(cls, tag_name: str) -> List['arcology.models.Page']:
return [
tag_obj.heading.path.page_set.first()
for tag_obj in cls.objects.filter(tag=tag_name).distinct()
])
]
@classmethod

View File

@ -119,7 +119,7 @@ This renders a partial depending on whether or not it's called by the HTMX decla
#+begin_src python :tangle sitemap/views.py :mkdirp yes
def tag_page(request, tag: str):
site = Site.from_request(request)
pages = Tag.pages_by_name(tag)
pages = Tag.weighted_pages_by_name(tag)
if request.htmx:
base_template = "sitemap/tag_partial.html"
@ -137,33 +137,58 @@ def tag_page(request, tag: str):
#+begin_src jinja2 :tangle sitemap/templates/sitemap/tag.html
{% extends base_template %}
{% load static %}
{% block h1 %}<h1>Pages tagged with {{tag}} in the Arcology<h1>{% endblock %}
{% block h1 %}<h1>{{site.title}}<h2>Pages tagged with {{tag}}</h2></h1>{% endblock %}
{% block title %}Pages tagged with {{tag}} in the Arcology{% endblock %}
{% block extra_head %}
<link rel="stylesheet" href="{% static 'sitemap/css/sitemap.css' %}"/>
<script src="{% static 'sitemap/js/htmx.js' %}" defer></script>
{% endblock %}
{% block content %}
<h1>Pages tagged with {{tag}}</h1>
<section>
<a href="/tags/">&larr;&nbsp;Show all tags</a>
<h1>Pages tagged with {{tag}}</h1>
{{ list() }}
{% endblock %}
{% block list %}
hi
<ul id="{{tag}}-pages">
{% for page in pages %}
<li><a href="{{page.to_url}}">{{page.title}}</a></li>
{% endfor %}
</ul>
{% block list %}
<ul id="{{tag}}-pages" class="tag-list">
{% for page, hit_count in pages.items %}
<li><a style="--size: {{hit_count}};" href="{{page.to_url}}">{{page.title}}</a></li>
{% endfor %}
</ul>
{% endblock %}
</section>
{% endblock %}
#+end_src
That =request.htmx= branch will make sure we only render the list if the HTMX partial is called by swapping the base HTML template to render only the list.
With some minor CSS rules applied we get a sort of limited "tag cloud" effect where pages with more links to this heading get made larger
#+begin_src css :tangle sitemap/static/sitemap/css/sitemap.css :mkdirp yes
ul.tag-list {
list-style: none;
padding-left: 0;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
ul.tag-list a {
--size: 1;
font-size: calc(log(var(--size) + 1) * 1rem);
}
#+end_src
That =request.htmx= branch will make sure we only render the list if the HTMX partial is called by swapping the base HTML template to render only the list:
#+begin_src jinja2 :tangle sitemap/templates/sitemap/tag_partial.html
<a href="/tags/{{ tag }}">Show all...</a>
{% block list %}{% endblock %}
#+end_src
* Sitemap JSON
That this relies on [[id:20240204T234334.762591][Data Models for Sites, Web Features, and Feeds]] *and* [[id:arcology/django/roam][Arcology Roam Models]] tells me it may be needs to be in a different module, idk... the structure of these projects really does need to be worked on.

View File

@ -0,0 +1,16 @@
/* [[file:../../../../sitemap.org::*Individual Tag Pages (and list partial)][Individual Tag Pages (and list partial):3]] */
ul.tag-list {
list-style: none;
padding-left: 0;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
ul.tag-list a {
--size: 1;
font-size: calc(log(var(--size) + 1) * 1rem);
}
/* Individual Tag Pages (and list partial):3 ends here */

View File

@ -1,21 +1,26 @@
{# [[file:../../../sitemap.org::*Individual Tag Pages (and list partial)][Individual Tag Pages (and list partial):2]] #}
{% extends base_template %}
{% load static %}
{% block h1 %}<h1>Pages tagged with {{tag}} in the Arcology<h1>{% endblock %}
{% block h1 %}<h1>{{site.title}}<h2>Pages tagged with {{tag}}</h2></h1>{% endblock %}
{% block title %}Pages tagged with {{tag}} in the Arcology{% endblock %}
{% block extra_head %}
<link rel="stylesheet" href="{% static 'sitemap/css/sitemap.css' %}"/>
<script src="{% static 'sitemap/js/htmx.js' %}" defer></script>
{% endblock %}
{% block content %}
<h1>Pages tagged with {{tag}}</h1>
<section>
<a href="/tags/">&larr;&nbsp;Show all tags</a>
<h1>Pages tagged with {{tag}}</h1>
{{ list() }}
{% endblock %}
{% block list %}
hi
<ul id="{{tag}}-pages">
{% for page in pages %}
<li><a href="{{page.to_url}}">{{page.title}}</a></li>
{% endfor %}
</ul>
{% block list %}
<ul id="{{tag}}-pages" class="tag-list">
{% for page, hit_count in pages.items %}
<li><a style="--size: {{hit_count}};" href="{{page.to_url}}">{{page.title}}</a></li>
{% endfor %}
</ul>
{% endblock %}
</section>
{% endblock %}
{# Individual Tag Pages (and list partial):2 ends here #}

View File

@ -1,3 +1,5 @@
{# [[file:../../../sitemap.org::*Individual Tag Pages (and list partial)][Individual Tag Pages (and list partial):3]] #}
{# [[file:../../../sitemap.org::*Individual Tag Pages (and list partial)][Individual Tag Pages (and list partial):4]] #}
<a href="/tags/{{ tag }}">Show all...</a>
{% block list %}{% endblock %}
{# Individual Tag Pages (and list partial):3 ends here #}
{# Individual Tag Pages (and list partial):4 ends here #}

View File

@ -32,7 +32,7 @@ def tags_index(request):
# [[file:../sitemap.org::*Individual Tag Pages (and list partial)][Individual Tag Pages (and list partial):1]]
def tag_page(request, tag: str):
site = Site.from_request(request)
pages = Tag.pages_by_name(tag)
pages = Tag.weighted_pages_by_name(tag)
if request.htmx:
base_template = "sitemap/tag_partial.html"