moved skeleton files to cache so that the python code doesn't need to be updated dynamically.

This commit is contained in:
Paul Houser 2024-07-10 14:52:38 -06:00
parent d6b96c3980
commit eaeaa67807
3 changed files with 17 additions and 23 deletions

View File

@ -18,6 +18,9 @@ A terminal-style home page replicating the tree command, modified from [this](ht
</div>
# Usage
## Requirements
Requires the `bs4` python package.
## Installation
To install StartTree for the first time, run the following commands:
(Note: If the `~/.config/StartTree` directory already exists, `init.sh` will not copy the example config to prevent accidentally overwriting a custom config. )
@ -50,7 +53,7 @@ tree_1: # each column should be named 'tree_X' where X is unique for each tree.
# or containing characters that cannot be in a yaml variable name.
frontpage:
- "https://www.reddit.com/"
- "front page" #
- "front page"
unixporn: "https://www.reddit.com/r/unixporn/"
tree_2:
other:
@ -80,10 +83,4 @@ vim docker-compose.yaml # edit specifics to your liking
docker-compose -f docker-compose.yaml up -d
```
This will make the `NGINX` server persist across reboots. You can point your browser's new tab and home page to `localhost:p<port#>` and you should see your startpage!
### NOTE:
Currently, docker is unaware if a file changes on the fly (like generating a new colorscheme or adding new shortcuts), so you have to restart the container with
`docker-compose -f docker-compose.yaml restart <servicename>`
This will make the `NGINX` server persist across reboots. You can point your browser's new tab and home page to `localhost:<port#>` and you should see your startpage!

View File

@ -1,7 +1,6 @@
#!/bin/python3
import yaml
import os
from os.path import expanduser
from shutil import copyfile
from bs4 import BeautifulSoup
@ -9,10 +8,6 @@ from bs4 import BeautifulSoup
# get home directory
home = expanduser("~")
# install script will fill this in
# replace line
repo_dir = "/home/paul/Documents/GitHub/StartTree"
# get config path
config_dir = home + '/.config/StartTree'
config_path = home + '/.config/StartTree/config.yaml'
@ -28,7 +23,6 @@ def prettifyHTML(html):
def parse_yaml():
with open(config_path, mode='r') as file:
file_dict = yaml.full_load(file)
file.close()
return file_dict
def print_keys(dictionary):
@ -78,7 +72,7 @@ def gen_html(file_dict):
print("Generating index.html...")
# open files
skeleton_html = open(repo_dir + '/skeletons/index.html', 'r')
skeleton_html = open(cache_dir + '/skeletons/index.html', 'r')
cache_html = open(cache_dir + '/index.html', 'w+')
# copy skeleton_html to cache_html until Column Start comment
@ -104,7 +98,7 @@ def gen_html(file_dict):
print("Done!")
def gen_style(file_dict):
skeleton_style = open(repo_dir + '/skeletons/style.css', 'r')
skeleton_style = open(cache_dir + '/skeletons/style.css', 'r')
cache_style = open(cache_dir + '/styles/style.css', 'w')
# find style attributes in file_dict
@ -119,7 +113,7 @@ def gen_style(file_dict):
if theme == "pywal":
theme = home + '/.cache/wal/colors.css'
else:
theme = repo_dir + '/themes/' + theme + '.css'
theme = cache_dir + '/themes/' + theme + '.css'
copyfile(theme, home + '/.cache/StartTree/styles/colors.css')

15
init.sh
View File

@ -4,10 +4,6 @@ config_dir=$HOME/.config/StartTree
config_path=$HOME/.config/StartTree/config.yaml
cache_dir=$HOME/.cache/StartTree
# install pip reqs
echo "Downloading pip dependencies..."
pip install --user bs4
# check if .config path exists
if [ ! -d "$HOME/.config" ]; then
echo "The directory '~/.config' does not exist, or you do not have permissions to edit it."
@ -20,6 +16,12 @@ if [ ! -d "$HOME/.cache" ]; then
exit
fi
# check if .local/bin exists
if [ ! -d "$HOME/.local/bin" ]; then
echo "The directory '~/.local/bin' does not exist, or you do not have permissions to edit it."
exit
fi
# check if .config/StartTree exists, create it and config if not
if [ ! -d "$config_dir" ]; then
echo "Creating '~/.config/StartTree'..."
@ -46,6 +48,9 @@ if [ ! -d "$cache_dir" ]; then
echo "Symlinking themes..."
ln -s $(pwd)/themes $HOME/.cache/StartTree/themes
echo "Symlinking skeleton files..."
ln -s $(pwd)/skeletons $HOME/.cache/StartTree/skeletons
echo "Creating '$cache_dir/styles'..."
mkdir "$cache_dir/styles"
fi
@ -64,5 +69,3 @@ echo "Make sure this directory is in your \$PATH"
FILEPATH=$(readlink -f "docker/data/default.conf")
ln -s $FILEPATH $HOME/.cache/StartTree/default.conf
sed -i "/# replace line/{n;s@.*@repo_dir = \"$(pwd)\"@}" generate.py