Adds documentation from tpo/web/wiki.wiki authored by Gaba's avatar Gaba
The Lektor-based sites predominently use Sass as a powerful CSS preprocessor. Because Sass is compiled, editing the styles of one of the Lektor sites requires a bit more work than editing a CSS file directly.
### Installing the Sass compiler
The javascript implementation of sass from npm doesn't compile our SCSS anymore, so you'll have to install the [dart sass compiler](https://github.com/sass/dart-sass). Here's a script to automate that process (don't forget to add the install directory to your path!):
```bash
#!/usr/bin/env bash
set -e
set -u
# replace with macos or windows (through something like cygwin) as appropriate
package_name='linux'
download_url=$(curl \
https://api.github.com/repos/sass/dart-sass/releases/latest \
| grep -E "browser_download_url.*$package_name-x64" \
| awk '{print $2}' \
| cut -d "\"" -f 2)
mkdir -p "$HOME/bin"
extension=$(echo $download_url | rev | cut -d '.' -f -2 | rev)
case "$extension" in
tar.gz)
curl -L "$download_url" | tar xvz --strip-components=1 -C "$HOME/bin" -- dart-sass/sass;;
zip)
tmpfile=$(mktemp /tmp/temporary_sass_download.XXXXXX.zip)
trap "rm -f $tmpfile" 0 2 3 15 # remove on exit
curl -L "$download_url" -o "$tmpfile"
unzip -p "$tmpfile" >&3 "$HOME/bin/sass"
;;
*)
echo "Unknown file extension" && exit 1;;
esac
chmod +x "$HOME/bin"
echo "sass installed to $HOME/bin, please make sure that directory is in your path"
```
### Editing and rebuilding Sass files
If you're editing a CSS file directly from the [lego repo][1], the following command will rebuild all the scss:
```bash
sass assets/scss:assets/static/css
```
More likely, you'll be making multiple changes from another repository that uses lego as a submodule.
In that case, the following command will automatically recompile any changed SCSS files:
```bash
sass --watch lego/assets/scss:lego/assets/static/css
```
Don't forget to commit your changes to the lego repo and make an MR when you're done!
```bash
cd lego
git add assets/scss
git commit
```
[1]: https://gitlab.torproject.org/tpo/web/lego/
### More Sass resources
- Install Sass: <https://sass-lang.com/install
- Learn Sass: <https://sass-lang.com/guide>
- Sass documentation: <https://sass-lang.com/documentation>