Compare commits

...

3 Commits

Author SHA1 Message Date
Ryan Rix 03fc25827c trying to clean u the deployment shit... 2024-02-15 15:47:57 -08:00
Ryan Rix cce504ed5e add <img> from arroyo and CSS to make it reasonable 2024-02-15 15:47:21 -08:00
Ryan Rix 6db1c1d23b add feeds.json endpoint and feed <meta> 2024-02-15 15:45:03 -08:00
10 changed files with 140 additions and 50 deletions

View File

@ -60,6 +60,14 @@ class Site(EMOM('site'), models.Model):
url = url + f"#{heading.node_id}"
return url
def urlize_feed(self, feed: Feed):
domain = self.sitedomain_set.first().domain
key_rest = feed.route_key.split("/", 1)[1]
url = f"https://{domain}/{key_rest}"
return url
@classmethod
def from_route(cls: Site, route_key: str) -> Site:
site_key = route_key.split("/")[0]
@ -290,6 +298,9 @@ class Feed(EMOM('feed'), models.Model):
title = models.CharField(max_length=512)
visibility = models.CharField(max_length=512, choices=POST_VISIBILITY)
def url(self):
return self.site.urlize_feed(self)
@classmethod
def create_from_arroyo(cls, doc: native.Document) -> Feed | None:
route_key = next(iter(doc.collect_keywords("ARCOLOGY_FEED")), None)
@ -531,6 +542,7 @@ urlpatterns = [
path("robots.txt", views.robots),
path("sitemap", views.sitemap, name="sitemap"),
path("sites.css", views.site_css, name="site-css"),
path("feeds.json", views.feed_list, name="feed-list"),
path("", include("django_prometheus.urls")),
# ensure these ones are last because they're greedy!
re_path("(?P<key>[0-9a-zA-Z/_\-]+\.xml)", views.feed, name="feed"),
@ -609,11 +621,14 @@ def render_page(request, site, full_key):
links = the_page.collect_links()
page_html = the_page.to_html(links)
feeds = site.feed_set.all()
page_counter.labels(page=full_key, status=200, site=site.key, agent_type=agent).inc()
return render(request, "arcology/page.html", dict(
site=site,
page=the_page,
feeds=feeds,
head_title=f"{the_page.title} - {site.title}",
html_content=page_html,
@ -754,8 +769,17 @@ Here are some [[https://medium.com/@massimo.cassandro/flexbox-separators-b284d6d
.content > *:first-child {
order: -1;
}
.content img {
display: block;
width: 80%;
margin: 0 auto;
}
#+end_src
And some simple image wrangling:
** INPROGRESS Atom Feed Handler
:PROPERTIES:
:ID: 20240204T234814.612917
@ -900,6 +924,30 @@ Disallow: /
{% endfor %}
#+end_src
** Feed discovery endpoint
:LOGBOOK:
CLOCK: [2024-02-15 Thu 14:17]--[2024-02-15 Thu 14:41] => 0:24
:END:
#+begin_src python :tangle arcology/views.py
import json
def feed_list(request):
site = Site.from_request(request)
feeds = Feed.objects.all()
ret = [
dict(
key=feed.route_key,
url=site.urlize_feed(feed),
title=feed.title,
site=feed.site.key,
visibility=feed.visibility,
)
for feed in feeds
]
return HttpResponse(json.dumps(ret), content_type="application/json")
#+end_src
** Arcology Site Templates
In short, there are four blocks that the page template and other templates will use to embed content in the rendered web page:

View File

@ -42,6 +42,14 @@ class Site(EMOM('site'), models.Model):
url = url + f"#{heading.node_id}"
return url
def urlize_feed(self, feed: Feed):
domain = self.sitedomain_set.first().domain
key_rest = feed.route_key.split("/", 1)[1]
url = f"https://{domain}/{key_rest}"
return url
@classmethod
def from_route(cls: Site, route_key: str) -> Site:
site_key = route_key.split("/")[0]
@ -180,6 +188,9 @@ class Feed(EMOM('feed'), models.Model):
title = models.CharField(max_length=512)
visibility = models.CharField(max_length=512, choices=POST_VISIBILITY)
def url(self):
return self.site.urlize_feed(self)
@classmethod
def create_from_arroyo(cls, doc: native.Document) -> Feed | None:
route_key = next(iter(doc.collect_keywords("ARCOLOGY_FEED")), None)

View File

@ -47,6 +47,12 @@ section.sidebar > div.backlinks {
.content > *:first-child {
order: -1;
}
.content img {
display: block;
width: 80%;
margin: 0 auto;
}
/* Org Page-specific CSS Stylings:3 ends here */
/* [[file:../../../../arcology.org::*CSS][CSS:1]] */

View File

@ -10,6 +10,7 @@ urlpatterns = [
path("robots.txt", views.robots),
path("sitemap", views.sitemap, name="sitemap"),
path("sites.css", views.site_css, name="site-css"),
path("feeds.json", views.feed_list, name="feed-list"),
path("", include("django_prometheus.urls")),
# ensure these ones are last because they're greedy!
re_path("(?P<key>[0-9a-zA-Z/_\-]+\.xml)", views.feed, name="feed"),

View File

@ -51,11 +51,14 @@ def render_page(request, site, full_key):
links = the_page.collect_links()
page_html = the_page.to_html(links)
feeds = site.feed_set.all()
page_counter.labels(page=full_key, status=200, site=site.key, agent_type=agent).inc()
return render(request, "arcology/page.html", dict(
site=site,
page=the_page,
feeds=feeds,
head_title=f"{the_page.title} - {site.title}",
html_content=page_html,
@ -142,6 +145,25 @@ def robots(request):
), content_type="text/plain")
# =robots.txt= Endpoint:1 ends here
# [[file:../arcology.org::*Feed discovery endpoint][Feed discovery endpoint:1]]
import json
def feed_list(request):
site = Site.from_request(request)
feeds = Feed.objects.all()
ret = [
dict(
key=feed.route_key,
url=site.urlize_feed(feed),
title=feed.title,
site=feed.site.key,
visibility=feed.visibility,
)
for feed in feeds
]
return HttpResponse(json.dumps(ret), content_type="application/json")
# Feed discovery endpoint:1 ends here
# [[file:../arcology.org::*Per-Site link color dynamic CSS endpoint][Per-Site link color dynamic CSS endpoint:1]]
def site_css(request):
sites = Site.objects.all()

View File

@ -21,8 +21,10 @@ python3.pkgs.buildPythonPackage rec {
]) ++ (with python3.pkgs; [
arrow
click
django
django_4
django-prometheus
(django-stubs-ext.override { django = django_4; })
(django-stubs.override { django = django_4; })
gunicorn
polling
setuptools

View File

@ -39,8 +39,6 @@ let
ARCOLOGY_DB_PATH = "${cfg.dataDir}/databases/arcology2.db";
ARCOLOGY_ALLOWED_HOSTS = concatStringsSep "," cfg.domains;
# ARCOLOGY_SYNCTHING_KEY=
# ALLOWED_HOSTS in to settings based on cfg.domains...
GUNICORN_CMD_ARGS = "--bind=${cfg.address}:${toString cfg.port} -w ${toString cfg.workerCount}";
};

View File

@ -6,11 +6,11 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1707114472,
"narHash": "sha256-yYDz01/0m1ObUU6ULCg1itjKnJWMu02GhG0E4etMA+0=",
"lastModified": 1708039372,
"narHash": "sha256-+Sg8VXqBKNOyRnTdxurtAKClysW7zE825JzujKHM34g=",
"ref": "refs/heads/main",
"rev": "f890e941bbcb4e3402a8c23464373badf1180065",
"revCount": 148,
"rev": "b83541271587e91e42a7306164b9dd8e23569811",
"revCount": 153,
"type": "git",
"url": "https://code.rix.si/rrix/arroyo"
},

View File

@ -72,8 +72,10 @@ python3.pkgs.buildPythonPackage rec {
]) ++ (with python3.pkgs; [
arrow
click
django
django_4
django-prometheus
(django-stubs-ext.override { django = django_4; })
(django-stubs.override { django = django_4; })
gunicorn
polling
setuptools
@ -90,6 +92,46 @@ python3.pkgs.buildPythonPackage rec {
}
#+end_src
** Dev Environment
=nix develop= or =nix-shell= will set you up with an environment that has Python programming dependencies available.
#+begin_src nix :tangle shell.nix
{ pkgs ? import <nixpkgs> {},
python3 ? pkgs.python3,
arroyo_rs ? pkgs.callPackage /home/rrix/org/arroyo/default.nix {},
}:
let
myPython = python3.withPackages( pp: with pp; [
pip
pytest
mypy
arrow
arroyo_rs
django_4
django-prometheus
(django-stubs-ext.override { django = django_4; })
(django-stubs.override { django = django_4; })
gunicorn
polling
]);
in pkgs.mkShell {
packages = (with pkgs; [
maturin
myPython
pyright
black]);
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
NIX_CONFIG = "builders =";
shellHook = ''
PYTHONPATH=${myPython}/${myPython.sitePackages}
'';
}
#+end_src
** A Flake to tie everything together and make it possible to run remotely
Nix is really going this direction, I'm not sure it's worthwhile but I'm going to see how to adapt to this world. It should be possible to =nix run= a few apps to be able to operate the arcology.
@ -139,46 +181,6 @@ Nix is really going this direction, I'm not sure it's worthwhile but I'm going t
}
#+end_src
** Dev Environment
=nix develop= or =nix-shell= will set you up with an environment that has Python programming dependencies available.
#+begin_src nix :tangle shell.nix
{ pkgs ? import <nixpkgs> {},
python3 ? pkgs.python3,
arroyo_rs ? pkgs.callPackage /home/rrix/org/arroyo/default.nix {},
}:
let
myPython = python3.withPackages( pp: with pp; [
pip
pytest
mypy
arrow
arroyo_rs
django_4
django-prometheus
django-stubs-ext.override { django = django_4; }
django-stubs.override { django = django_4; }
gunicorn
polling
]);
in pkgs.mkShell {
packages = (with pkgs; [
maturin
myPython
pyright
black]);
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
NIX_CONFIG = "builders =";
shellHook = ''
PYTHONPATH=${myPython}/${myPython.sitePackages}
'';
}
#+end_src
** Direnv
[[id:45fc2a02-fcd0-40c6-a29e-897c0ee7b1c7][direnv]] fucking rules.

View File

@ -14,8 +14,8 @@ let
arroyo_rs
django_4
django-prometheus
django-stubs-ext.override { django = django_4; }
django-stubs.override { django = django_4; }
(django-stubs-ext.override { django = django_4; })
(django-stubs.override { django = django_4; })
gunicorn
polling
]);