Likho’s microblog.py
Updated 2024 Jan 10 by Likho (licho@firemail.cc)
microblog.py
is a simple microblog generator
written in under 500 600 lines of Python.
If you use it, let me know. I can also add you to my webring.
git:https://notabug.org/likho/microblog.py
example: https://likho.neocities.org/microblog/
Features:
- pagination
- tag cloud
- webring
- configuration file
- sorting (backdating)
- mini-galleries
Perks over social media platforms.
- less drama
- not “software-as-a-service”
- self-stewardship of data
- no moderator abuse
- viewable on older computers and browsers
- low requirements
- doesn’t get invoked each visit (unlike f/CGI)
- doesn’t need to be run 24/7 (unlike web server application)
- doesn’t involve a relational database system
- doesn’t need javascript
Usage
microblog.py
assumes the user has a basic
understanding of HTML and CSS. There is no code specific to an
operating system, but Linux users would have the least trouble
running it.
See also https://notabug.org/likho/microblog.py#usage.
Getting Started
These are the sequence of commands to get started.
git clone https://notabug.org/likho/microblog.py microblog
cd microblog
cp example/Makefile .
make
This means to:
- download the program using a git client into a folder called
microblog
- enter the folder
microblog
- copy and paste the file
example/Makefile
into the current folder. - invoke
make
This should generate an example page named
result.html
which can be opened in a web browser for
preview. It should also avail the files template.tpl
,
timeline.css
, settings.toml
, and
content.txt
.
content.txt
is the user contentsettings.toml
is the configuration filetemplate.tpl
is the html page templatetimeline.css
is the style sheet that defines the layout and proportions of page elements; by default, it minimally defines color.
To help discern which elements are which, some borders in
result.html
are color-coded in red, blue, and
green.
If you don’t want to use Gnu Make…
make
is only there for convenience. If you want to
use another interface, this is the page generation command:
python microblog.py ./template.tpl ./content.txt > result.html
You can rename the files content.txt
,
template.tpl
, and result.html
however you
wish. These are only names provided by example.
Posting images
Images are inserted into posts automatically. For example if
content.txt
contains the following
Thu Mar 16 2:22:22 PM EDT 2022
I took these pictures.
/images/1.jpg /images/2.jpg /images/3.jpg
In this case, the images are rendered within the gallery and panel elements as
<a href="/images/1.jpg"><img src="/images/1.jpg" class="embed"></a>
and so on.
However, this is only adequate for images of small sizes such as
screenshots of old cartoons, books, or web pages. Note, relative
paths (e.g ./images/1.jpg
) may break on paginated posts
or tags.
Images with Thumbnails
See [post.gallery] in settings.toml
microblog.py
requires a thumbnail image and the
full-sized image to be of the same name but in different
folders.
An example:
Thu Mar 16 2:22:22 PM EDT 2022
I took these pictures.
1.jpg 2.jpg 3.jpg
If there is no symbol such as ‘.’ or ‘/’ that specifies a directory, a path based on user preferences will be prepended to the image file names, presumably for thumbnail and full-sized images.
Accepted Images
accepted_images
is a list of strings containing
recognized file extensions for images. By default, jpg and png are
provided.
Other Notes
microblog.py
does not manage or resize images for
the user.
The functionality can be added as a make
recipe.
Given three folders, import
(contains new, raw, or
uncompressed images), images
and
thumbs
,
# for each images in import
# resize to 720p or 140p and put it in a folder
SOURCE=$(shell ls import)
TOOL=magick
images:
for image in $(SOURCE) ; do \
$(TOOL) import/$$image -resize 1280x720 images/$$image;\
$(TOOL) import/$$image -resize 256x140 thumbs/$$image;\
done
Enable webring
See [webring] in settings.toml
Webring is disabled by default in settings.toml
. It
can be enabled by setting false
to
true
.
Adding to webring
The followers list is an array of strings.1
list= ["https://likho.neocities.org/microblog/meta.json"]
An array can also be broken into multiple lines.
list = [
"https://likho.neocities.org/microblog/meta.json",
"https://somewhere.else/microblog/meta.json"
]
See https://toml.io/en/v1.0.0#array for acceptable syntax.
You can add someone on an alternate DNS root like OpenNIC as long as your computer resolves the URL. Just don’t expect that same URL to resolve for everyone else visiting your page.
HTML Detection
Multiple lines of HTML can be included in notes without triggering automatic markup.
A few caveats:
- lines or phrases only containing tags such as
<i>
,<em>
,<b>
,<strong>
,<u>
,<s>
will still be marked up`automatically - attributes in
<pre>
and<code>
are not supported - unpaired tags must end with “/>” (e.g
<img src="image.jpg"/>
)
Good Practice
Keep content simple and maintainable.
Sat Nov 25 10:19:03 AM PST 2023
Test code block
<div style="overflow-x:scroll">
<pre>
<code>
#include <stdio.h>
int main(void) {
printf("Hello world! I am a C program.\n");
return 0;
}
</code>
</pre>
</div>
In this example, a code block has a long sentence which may trail
off to the sides on phones or other small devices.
overflow-x
adds a horizontal scroll bar so all text
remains within its containers. Ideally, don’t use
<div>
or <span>
unless
necessary. In most cases, overflow-x:scroll
is good
enough.
Not Recommended
The following may lead to bad results, more effort than necessary, or unmaintainability of the microblog or website. Generally, anything complex or fancy is better off as its own blog or page.
- any tags for headers such as h1, h2, or so on
- css rules to select specific posts within the microblog
- using the attribute “style” to define colors
Disclosures
The project uses pycurl and urllib for web requests.2
neouploader.py
, to upload files in bulk to
neocities, handles password using getpass.3
microblog.py
on the branch syndication
uses HTTP connections only to fetch data.4`
Proxy Behavior
microblog.py
supports proxied connections since the
branch syndication
had been merged to master.
Tor support can be enabled by setting either
http_proxy=socks://127.0.0.1:9050
https_proxy=socks://127.0.0.1:9050
As a result, the full script invocation will look like:
https_proxy=socks://127.0.0.1:9050 python microblog.py
The proxy resolves domain regardless of whether
socks://
or socks5h://
is specified.5
Common Errors
A key may be missing from your settings file (KeyError)
This most likely occurs after an update that added new
configuration options. The differences between the reference
settings.toml
and a user copy can be reviewed by the
following command.
diff example/settings.toml my/settings.toml
Why I’m not using the Fediverse
The foremost alternative to Twitter or Tumblr was the Fediverse, and I lost interest in the Fediverse for reasons as complex as the Fediverse is. But an approximation is that it is very easy to find poor administration or overbearing moderation in the Fediverse. The visibility of content is also subject to arbitrary white/blacklisting set by the administrator.6
I originally had profiles on gnusocial.no
and
sendero.social
. Both sites are offline now. However, I
also found myself a misfit in a culture of people who want
information delivered on a timeline.
https://notabug.org/likho/microblog.py/src/syndication/example/settings.toml#L44↩︎
https://notabug.org/likho/microblog.py/src/v0.1.0/neouploader.py#L2↩︎
https://notabug.org/likho/microblog.py/src/v0.1.0/neouploader.py#L39↩︎
https://notabug.org/likho/microblog.py/src/syndication/microblog.py#L378↩︎
https://notabug.org/likho/microblog.py/src/3bf37386fcd40d61ac529dc03e00db3085238ce9/microblog.py#L396↩︎