Bladeren bron

Render markdown files with a tool

Zed 4 jaren geleden
bovenliggende
commit
8c2e0c66e2
9 gewijzigde bestanden met toevoegingen van 45 en 21 verwijderingen
  1. 2 0
      .gitignore
  2. 4 4
      Dockerfile
  3. 2 1
      README.md
  4. 3 0
      nitter.nimble
  5. 0 7
      public/md/feature.md
  6. 3 1
      src/routes/unsupported.nim
  7. 7 8
      src/views/about.nim
  8. 14 0
      src/views/feature.nim
  9. 10 0
      tools/rendermd.nim

+ 2 - 0
.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

+ 4 - 4
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/

+ 2 - 1
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
 ```
 

+ 3 - 0
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"

+ 0 - 7
public/md/feature.md

@@ -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).

+ 3 - 1
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:

+ 7 - 8
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"
+    "<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 - 0
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"

+ 10 - 0
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