it's module time

This commit is contained in:
Anish Lakhwara 2022-04-16 12:27:47 +10:00
parent e787a657a7
commit c950ce40c9
7 changed files with 65 additions and 37 deletions

View file

@ -214,12 +214,13 @@ def get_tags(page):
def fix_images_urls(page):
regex = r"\!\[.*\]\((.*)\)"
matches = re.finditer(regex, page, re.MULTILINE)
media_folder = 'media/' # TODO bad hard code
for matchNum, match in enumerate(matches, start=1):
for groupNum in range(0, len(match.groups())):
captured_group = match.group(groupNum + 1)
if captured_group[:4] != "http":
full_url = build_url + config.medias_folder + captured_group
full_url = build_url + media_folder + captured_group
page = page.replace(captured_group, full_url)
return page
@ -303,8 +304,8 @@ def replacement_function(replace):
line2 = lines[1].split(',')
line1len = len(line1)
line2len = len(line2)
first = line1[random.randrange(line1len)]
second = line2[random.randrange(line2len)]
first = line1[random.randrange(line1len)].strip('\n')
second = line2[random.randrange(line2len)].strip('\n')
return first + ' ' + second
@ -535,8 +536,8 @@ def create_rss_feed(rss_entries, rss_template, rss_item_template, site_folder):
entry_template = itemTemplate
entry_template = entry_template.replace(
'rssItemTitle', rss_entry["title"])
entry_template = entry_template.replace('rssItemUrl', build_url +
rss_entry["slug"])
entry_template = entry_template.replace('rssItemUrl', build_url
+ rss_entry["slug"])
entry_template = entry_template.replace(
'rssItemDate', rss_entry["iso_date"])
entry_template = entry_template.replace(

BIN
basant/media/could.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
basant/media/does.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
basant/media/everything.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 KiB

BIN
basant/media/rocks.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View file

@ -50,11 +50,11 @@
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1649943612,
"narHash": "sha256-SDpQSBgNkfpBCIFnwH7gtDi+Ip0/3QdlGmiumM6W5xA=",
"lastModified": 1650035341,
"narHash": "sha256-vYtvVKRIrdOrsPKr1oVrTj7wzBKeips698TTc/e6gk4=",
"ref": "main",
"rev": "c18b26c49ece10fbd770d8422661c34363ecc199",
"revCount": 308,
"rev": "b6b97f649cd41a6dc19430e48a17fcb83a71f735",
"revCount": 324,
"type": "git",
"url": "ssh://gitea@git.sealight.xyz/aynish/kitaab"
},

View file

@ -59,35 +59,62 @@
'';
};
defaultPackage = self.packages.${system}.site;
#nixosModule = { options, lib, config, pkgs, ... }:
# let
# serverName = "anish.lakhwara.com";
# webRoot = "/var/www/${serverName}";
# serviceConfig = config.services."${serverName}";
# options = {
# enable = lib.mkEnableOption "${serverName} service";
# };
# in
# {
# options.services.${serverName} = options;
# config = lib.mkIf serviceConfig.enable {
# systemd.services."source-${serverName}" = {
# description = ''
# https://${serverName} source
# '';
# serviceConfig = {
# Type = "oneshot";
# };
# startAt = "*00:00:00";
# path = with pkgs; [ nix gnutar gzip curl jq ];
# script = ''
# set -ex
# Test container
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
self.nixosModule
({ pkgs, ... }: {
# Only allow this to boot as a container
boot.isContainer = true;
networking.hostName = "basant";
services."anish.lakhwara.com".enable = true;
})
];
};
# ln -sfT ${flake.packages.system.site} ${webRoot}
# '';
# };
# };
# };
# also need a module that refreshes this flake.lock, but maybe that shouldn't live here?
nixosModule = { options, lib, config, pkgs, ... }:
let
serverName = "anish.lakhwara.com";
webRoot = "/var/www/${serverName}";
serviceConfig = config.services."${serverName}";
options = {
enable = lib.mkEnableOption "${serverName} service";
};
in
{
options.services.${serverName} = options;
config = lib.mkIf serviceConfig.enable {
systemd.services."source-${serverName}" = {
description = ''
https://${serverName} source
'';
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
DynamicUser = "yes";
};
startAt = "*00:00:00";
path = with pkgs; [ nix gnutar gzip curl jq ] ++ [ self.packages.${system}.site ];
script = ''
set -ex
ln -sfT ${self.packages.${system}.site} ${webRoot}
'';
};
# Allow nginx through the firewall
networking.firewall.allowedTCPPorts = [ 80 ];
services.nginx.enable = true;
services.nginx.virtualHosts.${serverName} = {
forceSSL = true;
enableACME = true;
locations."/" = { root = "${webRoot}"; };
};
};
};
});
}