Render markdown files with a tool

This commit is contained in:
Zed 2022-01-09 23:14:01 +01:00
parent 1fc6a4092e
commit 8c2e0c66e2
9 changed files with 45 additions and 21 deletions

2
.gitignore vendored
View file

@ -5,5 +5,7 @@ nitter
/tests/geckodriver.log /tests/geckodriver.log
/tests/downloaded_files/* /tests/downloaded_files/*
/tools/gencss /tools/gencss
/tools/rendermd
/public/css/style.css /public/css/style.css
/public/md/*.html
nitter.conf nitter.conf

View file

@ -2,14 +2,14 @@ FROM nimlang/nim:1.6.2-alpine-regular as nim
LABEL maintainer="setenforce@protonmail.com" LABEL maintainer="setenforce@protonmail.com"
EXPOSE 8080 EXPOSE 8080
RUN apk --no-cache add libsass-dev RUN apk --no-cache add libsass-dev pcre
COPY . /src/nitter COPY . /src/nitter
WORKDIR /src/nitter WORKDIR /src/nitter
RUN nimble build -y -d:release -d:danger --passC:"-flto" --passL:"-flto" \ RUN nimble build -y -d:danger -d:lto -d:strip \
&& strip -s nitter \ && nimble scss \
&& nimble scss && nimble md
FROM alpine:latest FROM alpine:latest
WORKDIR /src/ WORKDIR /src/

View file

@ -84,7 +84,7 @@ Running it with the default config is fine, Nitter's default config is set to
use the default Redis port and localhost. use the default Redis port and localhost.
Here's how to create a `nitter` user, clone the repo, and build the project Here's how to create a `nitter` user, clone the repo, and build the project
along with the scss. along with the scss and md files.
```bash ```bash
# useradd -m nitter # useradd -m nitter
@ -93,6 +93,7 @@ $ git clone https://github.com/zedeus/nitter
$ cd nitter $ cd nitter
$ nimble build -d:release $ nimble build -d:release
$ nimble scss $ nimble scss
$ nimble md
$ cp nitter.example.conf nitter.conf $ cp nitter.example.conf nitter.conf
``` ```

View file

@ -29,3 +29,6 @@ requires "flatty#0.2.3"
task scss, "Generate css": task scss, "Generate css":
exec "nim c --hint[Processing]:off -d:danger -r tools/gencss" exec "nim c --hint[Processing]:off -d:danger -r tools/gencss"
task md, "Render md":
exec "nim c --hint[Processing]:off -d:danger -r tools/rendermd"

View file

@ -1,7 +0,0 @@
# Unsupported feature
Nitter doesn't support this feature yet, but it might in the future.
You can check for an issue and open one if needed here:
<https://github.com/zedeus/nitter/issues>
To find out more about the Nitter project, see the [About page](/about).

View file

@ -3,7 +3,9 @@ import jester
import router_utils import router_utils
import ../types import ../types
import ../views/[general, about] import ../views/[general, feature]
export feature
proc createUnsupportedRouter*(cfg: Config) = proc createUnsupportedRouter*(cfg: Config) =
router unsupported: router unsupported:

View file

@ -1,6 +1,6 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
import strformat import strformat
import karax/[karaxdsl, vdom], markdown import karax/[karaxdsl, vdom]
const const
date = staticExec("git show -s --format=\"%cd\" --date=format:\"%Y.%m.%d\"") date = staticExec("git show -s --format=\"%cd\" --date=format:\"%Y.%m.%d\"")
@ -8,9 +8,12 @@ const
link = "https://github.com/zedeus/nitter/commit/" & hash link = "https://github.com/zedeus/nitter/commit/" & hash
version = &"{date}-{hash}" version = &"{date}-{hash}"
let let about =
about = markdown(readFile("public/md/about.md")) try:
feature = markdown(readFile("public/md/feature.md")) readFile("public/md/about.html")
except IOError:
stderr.write "public/md/about.html not found, please run `nimble md`\n"
"<h1>About page is missing</h1><br><br>"
proc renderAbout*(): VNode = proc renderAbout*(): VNode =
buildHtml(tdiv(class="overlay-panel")): buildHtml(tdiv(class="overlay-panel")):
@ -19,7 +22,3 @@ proc renderAbout*(): VNode =
p: p:
text "Version " text "Version "
a(href=link): text version a(href=link): text version
proc renderFeature*(): VNode =
buildHtml(tdiv(class="overlay-panel")):
verbatim feature

14
src/views/feature.nim Normal file
View file

@ -0,0 +1,14 @@
# SPDX-License-Identifier: AGPL-3.0-only
import karax/[karaxdsl, vdom]
proc renderFeature*(): VNode =
buildHtml(tdiv(class="overlay-panel")):
h1: text "Unsupported feature"
p:
text "Nitter doesn't support this feature yet, but it might in the future. "
text "You can check for an issue and open one if needed here: "
a(href="https://github.com/zedeus/nitter/issues"):
text "https://github.com/zedeus/nitter/issues"
p:
text "To find out more about the Nitter project, see the "
a(href="/about"): text "About page"

10
tools/rendermd.nim Normal file
View file

@ -0,0 +1,10 @@
import std/[os, strutils]
import markdown
for file in walkFiles("public/md/*.md"):
let
html = markdown(readFile(file))
output = file.replace(".md", ".html")
output.writeFile(html)
echo "Rendered ", output