1
0
mirror of https://github.com/zedeus/nitter synced 2024-11-21 09:27:02 +01:00

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/downloaded_files/*
/tools/gencss
/tools/rendermd
/public/css/style.css
/public/md/*.html
nitter.conf

View File

@ -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/

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.
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
```

View File

@ -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"

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 ../types
import ../views/[general, about]
import ../views/[general, feature]
export feature
proc createUnsupportedRouter*(cfg: Config) =
router unsupported:

View File

@ -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"
"<h1>About page is missing</h1><br><br>"
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

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