<link rel="self" type="application/atom+xml" hreflang="" href="gemini://benjaminja.com/tags/capsule/feed.xml" />

<link rel="alternate" type="text/gemini" hreflang="" href="gemini://benjaminja.com/tags/capsule/" /><id>/</id>

2024-01-13T21:30:00Z

Hugo 0.129.0

<title><![CDATA[Rewriting my Site Generator]]></title>

  <link rel="alternate" type="text/gemini" hreflang="" href="gemini://benjaminja.com/log/2024/01/13-rewriting_site_gen/" />

<id>gemini://benjaminja.com/log/2024/01/13-rewriting_site_gen/</id>

<updated>2024-01-13T21:30:00Z</updated>

<summary type="gemini"><![CDATA[It’s a new year and a new me. Now that I have finally graduated, I feel that I have more time to work on my side projects. One of the first big things I have done is rewriting my site generator once again.

]]><![CDATA[It’s a new year and a new me. Now that I have finally graduated, I feel that I have more time to work on my side projects. One of the first big things I have done is rewriting my site generator once again.

=> Simple Site Generator

Rather than creating my own templating engine, I decided to use [tera].

=> tera

Keeping similar vibes to my original site generator: any additional features is implemented through shell scripts. There are a few important features baked in with the generator and all of the very site specific features are python scripts I created.

It is inspired by [kiln]

=> kiln

~~but from all of my research it seems that the site has gone down as well as the repo that was holding it.~~
Update 2024-01-16:
It turns out that source hut was hit by a DDoS attack and kiln was part of the cross-fire. Everything seems to be back up now.

Configuration

Here is a copy of my configuration file for https.

# Specify file structure content = "content"scripts = "scripts"templates = "templates"output = "www/html"static = "static"# file types that will be rendered in content directorytemplate_types = ["md", "gmi", "html", "xml"]
# Where the output will live on the web  root = "/"# The base url name for the websiteurl = "https://benjaminja.info"# Any scripts to run before renderingpre = [
"proc/pretty-url.py",
"proc/tags.py", # tags script creates the tag system for my log"proc/pretty-url.py",
]
# Any scripts to run after renderingpost = [
"proc/proc_html.py",
]
# After rendering a file, convert it using the provided convert for each file # type[converters]
md  =  { ext = "html", cmd = ["gmi-conv", "-i", "md",  "-o", "html"] }
gmi =  { ext = "html", cmd = ["gmi-conv", "-i", "gmi", "-o", "html"] }

As an example of what a file might go through, I will show you how this file gets rendered.

Let’s say that I have the text

{% raw -%} 
> The site was rendered at {{ now | ftime(fmt="%B %e, %Y @ %r %:z") }}
{%- endraw %}

Here is the output:

The site was rendered at {{ now | ftime(fmt="%B %e, %Y @ %r %:z") }}

First, the pretty-url.py script will be run which renames this file from content/log/2024/01/13-rewriting_site_gen.md to content/log/2024/01/13-rewriting_site_gen/index.md. After that the tags.py script will be run which adds this file to the capsule and projects tags. The pretty-url.py script gets run again for any generated files, then the rendering starts.

Since this is an md file, it will get rendered. After being rendered it will be converted to html using gmi-conv -i md -o html. (There is another configuration rendering to gemini). After it is converted, the file will be passed through several templates. To be specific:

  1. templates/logs/2024/_root.html which adds the title, date, and mentions.

  1. templates/_root.html which adds the base html boilerplate.

We’re not done yet, finally the proc_html.py script gets run. This will use beautiful soup to find any code blocks and adds formatting to it as well as differentiates gemini links as gemini links.

――――――――――――――――――――――――――――――――――――――――

I have two configurations running. One for html and one for gemini. I only need to write my capsule once and it will be rendered to both endpoints which is pretty nice.

Making this Publicly Available

There are still a few oddities about the software that I’m not very happy with. I also want to add a bunch of documentation so that you can actually know how to use it. So I won’t be releasing my site generator until it is in better shape.

This software is probably a bit into the “You need to be a computer wiz to use this software” territory, but If I were to add some sane 3rd party scripts and some good tutorials, I think it might could be usable by an average person.

=> 📭 Message me | 📝Or mention this post

]]>

<category term="capsule" label="Capsule" scheme="gemini://benjaminja.com/tags/capsule/" />

<category term="projects" label="Projects" scheme="gemini://benjaminja.com/tags/projects/" />

<published>2024-01-13T21:30:00Z</published></entry>

<title><![CDATA[Simple Site Generator]]></title>

  <link rel="alternate" type="text/gemini" hreflang="" href="gemini://benjaminja.com/log/2023/09/03-simple_site_gen/" />

<id>gemini://benjaminja.com/log/2023/09/03-simple_site_gen/</id>

<updated>2023-09-03T08:06:00Z</updated>

<summary type="gemini"><![CDATA[It’s been a while since I last posted. I have been busy working on my weatherstation. I’ll need to write about that soon, but for now I want to talk about the state of my capsule.

]]><![CDATA[It’s been a while since I last posted. I have been busy working on my weatherstation. I’ll need to write about that soon, but for now I want to talk about the state of my capsule.

During my breaks from the weatherstation, I have been working on my own site generator. I have finally got it to the point where I can start using it in production. There’s definitely a lot of work left to be done before I can publish it for others to use.

I have been calling it simple-site for now, though I’ll probably think of a better name when I actually release it. I have designed the generator to be as simple possible while allowing for complexity to come if desired.

The design starts out with templating. I designed my own simple templating engine that I found works surprisingly well. Each document will be rendered and passed to a chain of configured templates. To get added functionality, scripts can be created which will behave like functions in the templating engine. If you need more control, then generator scripts can be used to make alterations to the structure of the site.

Since I have migrated my capsule over to the new system, I have most likely missed a few things.

Example

Here is a pretty simple example of what my generator does. Hopefully it can help visualize what’s going on.

+- content
|  +- index.gmi
|  +- my-image.jpg
+- templates
|  +- base.gmi
+- site.toml
$ simple-site site.toml
Rendering "index.gmi"  with template "base.gmi"Copying "my-image.jpg"

Mentions

=> Rewriting my Site Generator

=> 📭 Message me | 📝Or mention this post

]]>

<category term="projects" label="Projects" scheme="gemini://benjaminja.com/tags/projects/" />

<category term="capsule" label="Capsule" scheme="gemini://benjaminja.com/tags/capsule/" />

<category term="gemini" label="Gemini" scheme="gemini://benjaminja.com/tags/gemini/" />

<published>2023-09-03T08:06:00Z</published></entry>

<title><![CDATA[How I deploy to my server]]></title>

  <link rel="alternate" type="text/gemini" hreflang="" href="gemini://benjaminja.com/log/2023/02/13-how_i_deploy/" />

<id>gemini://benjaminja.com/log/2023/02/13-how_i_deploy/</id>

<updated>2023-02-14T17:25:00Z</updated>

<summary type="gemini"><![CDATA[I don’t run this capsule on a server that I physically own. I rent out my server from digitalocean. Since my server doesn’t need to have lots of computing power or memory, I have opted to use the cheapest server possible that pennies can buy.

]]><![CDATA[I don’t run this capsule on a server that I physically own. I rent out my server from digitalocean. Since my server doesn’t need to have lots of computing power or memory, I have opted to use the cheapest server possible that pennies can buy. The only problem is that the server is so underpowered: it is nearly impossible to install software from source. In this log, I will explain how I go about deploying software to my server.

=> digitalocean.com

I’ve deployed my server as a droplet using a single shared CPU with 512 MB of memory. Because of these low specs, I have decided that all of my server/CGI software will run on native binaries to make using my capsule as smooth as possible.

The main server software that I use is made with Rust; a language known for its long and intensive compilations. I tried building it on my server and it took around 10 minutes before the build crashed from a lack of available memory. I would probably be better off cross compiling from my computer and uploading the binary than trying to find some workaround.

Uploading to the server

Compiling software for the server can vary widely from language to language, but it is almost always the same to upload your built binary to the server. The way I do it is by having a deploy.sh script in the root of a project that will build, upload, and install the software on the server.

BINARY=path/to/binary
REMOTE=root@my_server
BINAME="$(basename "$BINARY")"BINDIR=/usr/local/bin
TMPDIR=/var/tmp
# TODO Buildscp "$BINARY""$REMOTE:$TMPDIR/"ssh "$REMOTE""cd $TMPDIR && 
    install -Dm755 ./$BINAME$BINDIR/$BINAME &&
    rm ./$BINAME"

Of course depending on the type of software I’m deploying, the script may need to change to fit the project’s needs. I feel that it would be simpler to just scp the binary directly into the installed destination rather than installing it with a separate command, but I kind of like it.

Deploying Rust

Rust has become my goto language when it comes to compiled software. It supports a lot of language features that I like. It can feel like a high-level language while still allowing for low level control. My problem with Rust is with how difficult it is to cross compile. In theory, it is very easy to cross compile Rust, but when external libraries are used: the process becomes infinitely more complicated.

You will first need to install a target for your toolchain (This is fairly easy). If the program doesn’t use any external libraries, you should be good to go. Otherwise, you will need to install a C cross compiling toolchain (This can be tricky depending on your host system) and tell rust the linker you will be using in .cargo/config.toml. If your build still fails, a library might be compiling C from source, so you will need to tell rust that any C code should be built using your cross compiling toolchain in an environment variable. If you still can’t cross compile the software, then get ready for a never ending rabbit hole.

There is a tool that will help you do cross compiling that I wish I had known about before I spent a week learning how to do it manually. It is called “Cross”, and allows you to do cross compilations with very little hassle.

=> Cross

You will need to have Docker installed for Cross to work, but I think I have read that it might be possible to configure Cross to use Zig as a linker/compiler instead of building inside a Docker container.

Building with Cross is usually as simple as replacing cargo with cross. Depending on your needs, you may need to create a Cross.toml to customize your build, but that is still simpler than doing it manually.

TARGET=x86_64-unknown-linux-gnu
BINAME=
BINARY=target/release/$TARGET/$BINAME
cross build --release --target $TARGET

Deploying Go

In comparison to Rust, Go is a walk in the park. All that is needed to cross compile Go is two environment variables: GOOS and GOARCH. I don’t know if there are any edge cases that might show up when building. I really should learn Go.

BINAME=
BINARY=$BINAME
GOOS=linux GOARCH=amd64 go build

I haven’t needed to do anything else for Go to work, but I also don’t know the language. If it were possible to use external libraries, then I would imagine that cross compilation could get more complicated, but I just don’t know enough about the language to know if that’s even possible.

Deploying my capsule

This isn’t a language, but I figure it’s worth mentioning. When I deploy my capsule, I upload the project up to the server and then render it. This allows for semi-dynamic content that is stored exclusively on the server to be rendered into the capsule. The way I go about deploying the capsule is a little bit funky, but it works and that’s all that matters.

DIR="$(dirname -- "${BASH_SOURCE[0]}")"SERVER='gemini@my_server'DEST='/path/to/capsule/data/'SOURCE="$DIR/."GEMINI="/var/www/gemini/my.site/"COMMAND="${1:-upload}"# Upload to the serverif["$COMMAND"="upload"]; then# Synchronize the project with the server    rsync -rltp --delete-after -z --exclude='./git' --filter=':- .gitignore' -h "$SOURCE""$SERVER:$DEST"    echo "Uploaded capsule"# Run the build section of the deploy script on the server    ssh -t "$SERVER""cd $DEST ; ./deploy.sh build"elif["$COMMAND"="build"]; then# Render the capsule    cd "$DIR"    kiln build
    RES=$?
if[ $RES -ne 0]; then        exit $RES
fi# Copy the rendered files into the server folder    rsync -r "${DEST}public/""$GEMINI"    RES=$?
if[ $RES -ne 0]; then        exit $RES
fielse    echo "Invalid Command, should be one of [upload, build]"fi

I haven’t yet had the chance to deploy any other types of software, but I can imagine that some will be easier than others. Zig should be pretty simple, but C/C++ scares me. The thought of having to find or build libraries does not seem at all fun. Though C/C++ should still be easier than Rust.

=> 📭 Message me | 📝Or mention this post

]]>

<category term="projects" label="Projects" scheme="gemini://benjaminja.com/tags/projects/" />

<category term="capsule" label="Capsule" scheme="gemini://benjaminja.com/tags/capsule/" />

<category term="gemini" label="Gemini" scheme="gemini://benjaminja.com/tags/gemini/" />

<published>2023-02-14T17:25:00Z</published></entry>

<title><![CDATA[My Capsule Plans]]></title>

  <link rel="alternate" type="text/gemini" hreflang="" href="gemini://benjaminja.com/log/2023/02/10-capsule_plans/" />

<id>gemini://benjaminja.com/log/2023/02/10-capsule_plans/</id>

<updated>2023-02-10T19:20:00Z</updated>

<summary type="gemini"><![CDATA[I have been getting fairly ambitious with ideas for my capsule. This is dangerous with me being in the middle of a heavy semester, so I am going to write down my plans and implement them later.

]]><![CDATA[I have been getting fairly ambitious with ideas for my capsule. This is dangerous with me being in the middle of a heavy semester, so I am going to write down my plans and implement them later. Hopefully I don’t end up working on these projects to avoid my schoolwork (I am writing this very log to distract myself from a project I need to do 🙃).

Serve my content on both gemini and https

At the moment, I am serving my capsule on the www under a proxy. This has been good, but I would like to have more control of how it looks. To do this, I want to serve my capsule natively on both gemini and https protocols.

I want the feel of the web version to be simple, but feel like it was meant for the web. Primarily so that I can have a navigation section and inline images.

If I were to do this, I might need to write most of my content in markdown so that I can convert it into http/gemtext without much fuss.

Automated Gemmentions implementation

=> Gemini Mentions RFC

Seeing some of the implementations of gemini mentions has been really good. Notably Sean’s implementation where mentions to a post are placed at the bottom of the page under ‘Discussions about this entry’. I particularly like how it feels like I’m going through a big discussion thread without the need of looking through an aggregator.

=> Thoughts on an implementation of Gemini mentions (The post where I first saw mentions being used)

I want to have a feature like this myself, but I also don’t want to do any of it by hand. The idea would be to have a gemmention CGI script that adds mentioned pages to a database, then ask the site generator to rebuild the capsule (Any mentions would be placed in a footing after the article).

I’ve already written a CGI program that can upload mentions to a database, but I have yet to figure out how to insert mentions into posts. I would like to make the program portable so that anyone who would like to have similar functionality could do it themselves. The only problem is that the software I wrote is too complicated to publish without a lot of simplifications.

Aggregate topics

On most of my pages, I have added a little topics section at the top of the page. I want to have a section of my capsule where you can sort by similar topics.

I would have tags stored in the frontmatter and my site generator could generate pages for each topic. Also the title, date, and tags could be automatically inserted into the generated gemini files so I don’t have to repeat myself too much.

An example of the frontmatter might be like:

---
title: My Capsule Plans
date: 2023-02-10T12:20:00-07:00
tags:
- plans
- capsule
author: ttocsneb
---
I have been getting fairly ambitious with ideas for my capsule...

Learn the ins and outs of Kiln

=> Kiln

I am currently using Kiln to build my capsule. It has been great so far, but there are a few features that confuse me. I think that most of my problems lie in the fact that I am not familier with the Go templating engine.

I know that I can use kiln to build an alternative http format, but I’m not sure whether it will be able to do what I want with gemmentions and topics. I think it should be possible using the templating engine, but I will need to do research to verify. If I end up not being able to do these things, then I might design my own site generator inspired by Kiln, maybe something with python and jinja2.

=> 📭 Message me | 📝Or mention this post

]]>

<category term="plans" label="Plans" scheme="gemini://benjaminja.com/tags/plans/" />

<category term="capsule" label="Capsule" scheme="gemini://benjaminja.com/tags/capsule/" />

<category term="gemini" label="Gemini" scheme="gemini://benjaminja.com/tags/gemini/" />

<published>2023-02-10T19:20:00Z</published></entry>

Proxy Information
Original URL
gemini://benjaminja.com/tags/capsule/feed.xml
Status Code
Success (20)
Meta
text/xml
Capsule Response Time
885.494954 milliseconds
Gemini-to-HTML Time
5.00138 milliseconds

This content has been proxied by September (3851b).