Skip to content

Commit

Permalink
Render markdown files with a tool
Browse files Browse the repository at this point in the history
  • Loading branch information
zedeus committed Jan 9, 2022
1 parent 1fc6a40 commit 8c2e0c6
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ nitter
/tests/geckodriver.log
/tests/downloaded_files/*
/tools/gencss
/tools/rendermd
/public/css/style.css
/public/md/*.html
nitter.conf
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ FROM nimlang/nim:1.6.2-alpine-regular as nim
LABEL maintainer="[email protected]"
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/
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```

Expand Down
3 changes: 3 additions & 0 deletions nitter.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 0 additions & 7 deletions public/md/feature.md

This file was deleted.

4 changes: 3 additions & 1 deletion src/routes/unsupported.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 7 additions & 8 deletions src/views/about.nim
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# 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\"")
hash = staticExec("git show -s --format=\"%h\"")
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")):
Expand All @@ -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 changes: 14 additions & 0 deletions src/views/feature.nim
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions tools/rendermd.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8c2e0c6

Please sign in to comment.