Personal website with markdown blog & syntax highlighting
Go to file
Adam Piontek 9d2e0c5379 fixing purgecss issue with chroma styles 2021-04-06 11:22:05 -04:00
assets fixing purgecss issue with chroma styles 2021-04-06 11:22:05 -04:00
config fixing purgecss issue with chroma styles 2021-04-06 11:22:05 -04:00
lib updated to use golang chroma instead of python pygments 2021-04-06 10:42:15 -04:00
priv new post & changes 2021-04-06 00:25:35 -04:00
test added content, post display 2021-04-03 23:22:35 -04:00
.formatter.exs initial commit 2021-03-28 21:12:55 -04:00
.gitignore fixing purgecss issue with chroma styles 2021-04-06 11:22:05 -04:00
.iex.exs syntax highlighting and blog/post liveviews working; numerous other styling updates 2021-04-05 16:51:59 -04:00
README.md fixing purgecss issue with chroma styles 2021-04-06 11:22:05 -04:00
mix.exs added content, post display 2021-04-03 23:22:35 -04:00
mix.lock syntax highlighting and blog/post liveviews working; numerous other styling updates 2021-04-05 16:51:59 -04:00

README.md

Home73k

Personal website with blog.

Blog posts

Posts are markdown files stored under priv/content and parsed by Earmark. This can be configured in config.exs under config :home73k, :app_global_vars, blog_content: "path/to/content"

Syntax highlighting

For the challenge of it, and to keep user's browsers from having to run javascript just to highlight some code, I chose to do server-side syntax highlighting.

Due to the lexer limitations of elixir-native solutions, the highlighter uses Pygments by calling pygmentize via System.cmd

However, this requires installing python3 & Pygments. Best way to do this is with a venv (virtual python environment), so you'll also want python3-venv installed on a debian system, for example.

By default, Home73k is configured to look for pygmentize in a venv at priv/pygments/bin/pygmentize -- here's a quick howto for how to set that up:

cd priv
python3 -m venv pygments
source pygments/bin/activate
pip3 install Pygments

The location of bin/pygmentize can be configured in config.exs under config :home73k, :app_global_vars, pygmentize_bin: "path/to/bin/pygmentize"

Deploying

New versions

When improvements are made, we can update the deployed version like so:

cd /opt/home73k
git pull
mix deps.get --only prod
MIX_ENV=prod mix compile
# update chroma in priv gopath
GOPATH=$(pwd)/priv/go go get -u github.com/alecthomas/chroma/cmd/chroma
# rebuild static assets:
rm -rf priv/static/*
npm run deploy --prefix ./assets
MIX_ENV=prod mix phx.digest
MIX_ENV=prod mix release --overwrite
# test starting it:
MIX_ENV=prod _build/prod/rel/home73k/bin/home73k start

systemd unit:

[Unit]
Description=Home73k service
After=local-fs.target network.target

[Service]
Type=simple
User=runuser
Group=runuser
WorkingDirectory=/opt/home73k/_build/prod/rel/home73k
ExecStart=/opt/home73k/_build/prod/rel/home73k/bin/home73k start
ExecStop=/opt/home73k/_build/prod/rel/home73k/bin/home73k stop
#EnvironmentFile=/etc/default/myApp.env
Environment=LANG=en_US.utf8
Environment=MIX_ENV=prod
#Environment=PORT=4000
LimitNOFILE=65535
UMask=0027
SyslogIdentifier=home73k
Restart=always

[Install]
WantedBy=multi-user.target

nginx config:

    upstream phoenixhome {
      server 127.0.0.1:4721 max_fails=5 fail_timeout=60s;
    }
    server {
      location / {
        allow all;
        # Proxy Headers
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Cluster-Client-Ip $remote_addr;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_redirect off;
        # WebSockets
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://phoenixhome;
      }
    }