Compare commits

...

2 Commits

Author SHA1 Message Date
Ryan Rix 447a33f901 add feeds.json endpoint and feed <meta> 2024-02-15 14:33:27 -08:00
Ryan Rix fd6f77c677 move the user-configuration for the service deployment in to configuration.nix 2024-02-15 14:32:18 -08:00
6 changed files with 122 additions and 33 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):
self.site.ur
@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,
@ -900,6 +915,30 @@ Disallow: /
{% endfor %}
#+end_src
** Feed discovery endpoint
:LOGBOOK:
CLOCK: [2024-02-15 Thu 14:17]
: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

@ -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

@ -7,6 +7,9 @@
#+ARCOLOGY_KEY: arcology/django/configuration
,#+AUTO_TANGLE: vars:org-babel-default-header-args
#+ARROYO_NIXOS_MODULE: nixos/arcology2.nix
#+ARROYO_NIXOS_ROLE: server
user-configuration ; These are mostly generated from org-mode tables if you're meant to be editing or extending them. This is a cool feature of org-babel, where you can use tables as data for code which can output more code or even org headings or links. We use this to generate configuration.
* The Arcology's Site List
@ -137,6 +140,34 @@ Note that they're basically the same, but you can customize it further to your s
<<mk-site-colors(site-colors, "arcology")>>
#+end_src
* Deploy manifests for [[id:arroyo/nixos][Arroyo NixOS Generator]] or your own manifests
The [[id:arroyo/nixos][Arroyo NixOS Generator]] will integrate this or you can do this yourself. just import the nixos module above, and then configure it as below:
#+begin_src nix :tangle ~/arroyo-nix/nixos/arcology2.nix :noweb yes
{ pkgs, ... }:
let
arroyo_rs = pkgs.callPackage /home/rrix/org/arroyo/default.nix {};
arcology = pkgs.callPackage /home/rrix/org/arcology-django/default.nix { inherit arroyo_rs; };
in {
imports = [ ./arcology2-module.nix ];
services.arcology.enable = pkgs.lib.mkForce false;
services.arcology-ng = {
enable = true;
packages.arcology = arcology;
domains = pkgs.lib.splitString "," "<<get_allowed_hosts()>>";
orgDir = "/media/org";
folderId = "p1kld-oxnwd";
dataDir = "/srv/arcology";
};
}
#+end_src
The NixOS module which defines =services.arcology-ng= is in [[id:20240213T124300.774781][Deploying the Arcology]].
** NEXT the package import needs to be much better than this.
* Service Configuration
:PROPERTIES:
:ID: 20231217T155611.177995

View File

@ -5,9 +5,6 @@
#+filetags: :Project:
#+ARCOLOGY_KEY: arcology/django/deploy
#+ARROYO_NIXOS_MODULE: nixos/arcology2.nix
#+ARROYO_NIXOS_MODULE: nixos/arcology2-module.nix
#+ARROYO_NIXOS_ROLE: server
* NEXT Bootstrapping on non-NixOS
@ -15,7 +12,9 @@
* Running on [[id:20211120T220054.226284][The Wobserver]], self-hosting Arcology with the [[id:arroyo/django/generators][The Arroyo Generators]]
Package building is handled in the [[id:arcology/django/scaffolding][Arcology Project Scaffolding]]..
Package building is handled in the [[id:arcology/django/scaffolding][Arcology Project Scaffolding]].
Deployment declaration is in the [[id:arcology/django/config][Arcology Project Configuration]].
** NixOS module
@ -39,7 +38,6 @@ let
ARCOLOGY_STATIC_ROOT = cfg.staticRoot;
ARCOLOGY_DB_PATH = "${cfg.dataDir}/databases/arcology2.db";
ARCOLOGY_SYNCTHING_KEY = "ECNPVaubstVw34DFpeKAZfKLyGxipWiW";
ARCOLOGY_ALLOWED_HOSTS = concatStringsSep "," cfg.domains;
# ARCOLOGY_SYNCTHING_KEY=
# ALLOWED_HOSTS in to settings based on cfg.domains...
@ -71,6 +69,7 @@ let
User = "arcology";
Group = "arcology";
WorkingDirectory = cfg.dataDir;
EnvironmentFile = cfg.environmentFile;
# hardening...
};
};
@ -87,6 +86,7 @@ let
User = "arcology";
Group = "arcology";
WorkingDirectory = cfg.dataDir;
EnvironmentFile = cfg.environmentFile;
# hardening...
};
};
@ -176,6 +176,18 @@ in {
'';
};
environmentFile = mkOption {
type = types.path;
default = "${cfg.dataDir}/env";
description = mdDoc ''
A file containing environment variables you may not want to put in the nix store.
For example, put a syncthing key in there:
ARCOLOGY_SYNCTHING_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
'';
};
staticRoot = mkOption {
type = types.path;
default = "/var/lib/arcology/static/";
@ -232,36 +244,9 @@ probably just =getFlake= but augh.
*** INPROGRESS static files under gunicorn/nginx
:LOGBOOK:
- State "INPROGRESS" from "NEXT" [2024-02-15 Thu 12:08]
CLOCK: [2024-02-15 Thu 12:08]
CLOCK: [2024-02-15 Thu 12:08]--[2024-02-15 Thu 12:58] => 0:50
:END:
*** NEXT secret infrastructure for the syncthing key
or a way to load that in to the DB 🤔
** Arroyo NixOS snippet & my deployment configuration
The [[id:arroyo/nixos][Arroyo NixOS Generator]] will integrate this or you can do this yourself. just import the nixos module above, and then configure it as below:
#+begin_src nix :tangle ~/arroyo-nix/nixos/arcology2.nix
{ pkgs, ... }:
let
arroyo_rs = pkgs.callPackage /home/rrix/org/arroyo/default.nix {};
arcology = pkgs.callPackage /home/rrix/org/arcology-django/default.nix { inherit arroyo_rs; };
in {
services.arcology-ng = {
enable = true;
packages.arcology = arcology;
domains = [
"engine2.arcology.garden"
"v2.thelionsrear.com"
"v2.arcology.garden"
"cce2.whatthefuck.computer"];
orgDir = "/media/org";
folderId = "p1kld-oxnwd";
dataDir = "/srv/arcology";
};
}
#+end_src
*** NEXT the package import needs to be much better than this.