From 8c2e0c66e271673a9dfe0bad22b523e4d2799049 Mon Sep 17 00:00:00 2001 From: Zed Date: Sun, 9 Jan 2022 23:14:01 +0100 Subject: [PATCH] Render markdown files with a tool --- .gitignore | 2 ++ Dockerfile | 8 ++++---- README.md | 3 ++- nitter.nimble | 3 +++ public/md/feature.md | 7 ------- src/routes/unsupported.nim | 4 +++- src/views/about.nim | 15 +++++++-------- src/views/feature.nim | 14 ++++++++++++++ tools/rendermd.nim | 10 ++++++++++ 9 files changed, 45 insertions(+), 21 deletions(-) delete mode 100644 public/md/feature.md create mode 100644 src/views/feature.nim create mode 100644 tools/rendermd.nim diff --git a/.gitignore b/.gitignore index 967cc65..4d742bb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,7 @@ nitter /tests/geckodriver.log /tests/downloaded_files/* /tools/gencss +/tools/rendermd /public/css/style.css +/public/md/*.html nitter.conf diff --git a/Dockerfile b/Dockerfile index 3971a89..60aac63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,14 +2,14 @@ FROM nimlang/nim:1.6.2-alpine-regular as nim LABEL maintainer="setenforce@protonmail.com" EXPOSE 8080 -RUN apk --no-cache add libsass-dev +RUN apk --no-cache add libsass-dev pcre COPY . /src/nitter WORKDIR /src/nitter -RUN nimble build -y -d:release -d:danger --passC:"-flto" --passL:"-flto" \ - && strip -s nitter \ - && nimble scss +RUN nimble build -y -d:danger -d:lto -d:strip \ + && nimble scss \ + && nimble md FROM alpine:latest WORKDIR /src/ diff --git a/README.md b/README.md index ef2468e..ddae3d5 100644 --- a/README.md +++ b/README.md @@ -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. 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 # useradd -m nitter @@ -93,6 +93,7 @@ $ git clone https://github.com/zedeus/nitter $ cd nitter $ nimble build -d:release $ nimble scss +$ nimble md $ cp nitter.example.conf nitter.conf ``` diff --git a/nitter.nimble b/nitter.nimble index c83437b..428c308 100644 --- a/nitter.nimble +++ b/nitter.nimble @@ -29,3 +29,6 @@ requires "flatty#0.2.3" task scss, "Generate css": 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" diff --git a/public/md/feature.md b/public/md/feature.md deleted file mode 100644 index d12b883..0000000 --- a/public/md/feature.md +++ /dev/null @@ -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: - - -To find out more about the Nitter project, see the [About page](/about). diff --git a/src/routes/unsupported.nim b/src/routes/unsupported.nim index 4bafb96..0c085d4 100644 --- a/src/routes/unsupported.nim +++ b/src/routes/unsupported.nim @@ -3,7 +3,9 @@ import jester import router_utils import ../types -import ../views/[general, about] +import ../views/[general, feature] + +export feature proc createUnsupportedRouter*(cfg: Config) = router unsupported: diff --git a/src/views/about.nim b/src/views/about.nim index 7bf1d0e..77f92fa 100644 --- a/src/views/about.nim +++ b/src/views/about.nim @@ -1,6 +1,6 @@ # SPDX-License-Identifier: AGPL-3.0-only import strformat -import karax/[karaxdsl, vdom], markdown +import karax/[karaxdsl, vdom] const 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 version = &"{date}-{hash}" -let - about = markdown(readFile("public/md/about.md")) - feature = markdown(readFile("public/md/feature.md")) +let about = + try: + readFile("public/md/about.html") + except IOError: + stderr.write "public/md/about.html not found, please run `nimble md`\n" + "

About page is missing



" proc renderAbout*(): VNode = buildHtml(tdiv(class="overlay-panel")): @@ -19,7 +22,3 @@ proc renderAbout*(): VNode = p: text "Version " a(href=link): text version - -proc renderFeature*(): VNode = - buildHtml(tdiv(class="overlay-panel")): - verbatim feature diff --git a/src/views/feature.nim b/src/views/feature.nim new file mode 100644 index 0000000..5767024 --- /dev/null +++ b/src/views/feature.nim @@ -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" diff --git a/tools/rendermd.nim b/tools/rendermd.nim new file mode 100644 index 0000000..3afc447 --- /dev/null +++ b/tools/rendermd.nim @@ -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