Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move css, fonts, js to assets folder; auto install assets folder #19

Merged
merged 41 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f3dcc4e
move css, fonts, js to assets folder; auto install assets folder
Clonkk Jun 1, 2021
a679fad
add -f to publishers to resolve name conflict (index.nim) between pro…
Clonkk Jun 1, 2021
5ce2987
remove reliance on Nimble
Clonkk Jun 1, 2021
0153d31
only remove assets explicitly
Clonkk Jun 1, 2021
9a81634
Moved mustache template to src folder that gets deployes on Book crea…
Clonkk Jun 1, 2021
0730ff2
added comment to not forget debug comment
Clonkk Jun 1, 2021
1684fb3
rm debugEcho
Clonkk Jun 1, 2021
09c4f6e
added examples folder for a out of repo, example
Clonkk Jun 1, 2021
8ea9369
added validation CI
Clonkk Jun 1, 2021
b7b8afb
Added getEnv / putEnv mechanism to avoid findNimbleDir while propagat…
Clonkk Jun 1, 2021
37e8818
camelCase cariable, remove some debugEcho
Clonkk Jun 1, 2021
0fdd3b5
dirExists -> not dirExists for init check
Clonkk Jun 1, 2021
357be94
re-add entries
Clonkk Jun 2, 2021
69e93f0
move assets to ressources folder
Clonkk Jun 2, 2021
1f098b7
add relative path book.json
Clonkk Jun 2, 2021
f004e8d
Use non compile time value to prepare for CLI; this means it depends …
Clonkk Jun 2, 2021
3815211
uncomment book.json deletion
Clonkk Jun 2, 2021
04dfae4
fix missing nimble files with a placeholder until bugs gets fixe in N…
Clonkk Jun 2, 2021
778fc24
CLI prototype
Clonkk Jun 2, 2021
3796311
fixed clean
Clonkk Jun 2, 2021
8301864
add hints:off and verbosity to 0 in publiushers, remove some debug Echo
Clonkk Jun 2, 2021
31b0818
fix nimble tasks
Clonkk Jun 2, 2021
27c16e1
fix init
Clonkk Jun 2, 2021
b3096f2
fix github actions (I think)
Clonkk Jun 2, 2021
ed039b3
this repo uses main instead of master
Clonkk Jun 2, 2021
e70e18a
clean up
Clonkk Jun 3, 2021
ec91fa6
template -> templates; ressources -> resources
Clonkk Jun 3, 2021
2b2ee31
unbreak CI
Clonkk Jun 3, 2021
7dd8428
fix nimble file required and update nimib version to v0.1.3
Clonkk Jun 4, 2021
cf86eaa
nimble srcpretty
Clonkk Jun 4, 2021
549efed
improve readme and printHelp
Clonkk Jun 4, 2021
72a79ff
update readme
Clonkk Jun 4, 2021
3f8bbb4
rename env variable to variable name for clarity
Clonkk Jun 4, 2021
1e2b356
fix links & template missing an 's'
Clonkk Jun 4, 2021
46e685a
update readme
Clonkk Jun 4, 2021
8e1b67d
fix js path
Clonkk Jun 4, 2021
3845ccb
fix force args in populateAssets not overriding mustache files
Clonkk Jun 4, 2021
a34fa4b
nbBookTasks -> nimibookCli; README improvement
Clonkk Jun 4, 2021
9256b48
fix CI failures related to book variable
Clonkk Jun 4, 2021
4a11ff6
add examples in readme
Clonkk Jun 4, 2021
9acda49
md syntax is hard
Clonkk Jun 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
!docs/.gitignore
!docs/css
!docs/FontAwesome
!docs/fonts
!docs/js
docs/
book/book.json
book/book.json
28 changes: 14 additions & 14 deletions book/document.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@

{{&favicon_escaped}}
{{#favicon_svg}}
<link rel="icon" href="{{ path_to_root }}favicon.svg">
<link rel="icon" href="{{ path_to_root }}assets/favicon.svg">
{{/favicon_svg}}
{{#favicon_png}}
<link rel="shortcut icon" href="{{ path_to_root }}favicon.png">
<link rel="shortcut icon" href="{{ path_to_root }}assets/favicon.png">
{{/favicon_png}}
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/variables.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/general.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/chrome.css">
{{#print_enable}}
<link rel="stylesheet" href="{{ path_to_root }}css/print.css" media="print">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/print.css" media="print">
{{/print_enable}}

<!-- Fonts -->
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.min.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/FontAwesome/css/font-awesome.min.css">
{{#copy_fonts}}
<link rel="stylesheet" href="{{ path_to_root }}fonts/fonts.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/fonts/fonts.css">
{{/copy_fonts}}

<!-- Highlight.js Stylesheets - I could use nimib native highlight but let's keep it for styling... -->
<link rel="stylesheet" href="{{ path_to_root }}css/highlight.css">
<link rel="stylesheet" href="{{ path_to_root }}css/tomorrow-night.css">
<link rel="stylesheet" href="{{ path_to_root }}css/ayu-highlight.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/highlight.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/tomorrow-night.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/ayu-highlight.css">

<!-- Custom theme stylesheets - why the "../"? -->
{{#additional_css}}
<link rel="stylesheet" href="../{{ path_to_root }}{{ . }}">
Expand All @@ -58,7 +58,7 @@
<body>
<!-- Provide site root to javascript -->
<script type="text/javascript">
var path_to_root = "{{ path_to_root }}";
var path_to_root = "{{ path_to_root }}/assets";
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "{{ preferred_dark_theme }}" : "{{ default_theme }}";
</script>

Expand Down Expand Up @@ -311,4 +311,4 @@
{{/is_print}}

</body>
</html>
</html>
2 changes: 1 addition & 1 deletion book/index.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ proc readFileUntil(filename: string, text: string): string =
result &= line & '\n'

nbText: "../README.md".readFileUntil("<!--SKIP")
nbSave
nbSave
4 changes: 3 additions & 1 deletion genbook.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import nimibook, os # os is used inside Toc DSL

initBook

var book = newBookFromToc("nimibook", "book"):
section("Introduction", "index"): # .nim extension is optional
entry("Content", "content")
Expand All @@ -13,4 +15,4 @@ var book = newBookFromToc("nimibook", "book"):
draft("Draft chapter", "draft.md")

book.git_repository_url = "https://github.com/pietroppeter/nimibook"
nbBookTasks
nbBookTasks
31 changes: 18 additions & 13 deletions nimibook.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,32 @@ requires "nimib >= 0.1.2"
requires "jsony >= 1.0.1"

import os

task genbook, "build book":
selfExec(" r -d:release genbook.nim")

task dumpbook, "dump book.json":
selfExec(" r -d:release -d:dumpBook genbook.nim")

task cleanbook, "remove all files created during build":
# Since assets now gets populated, I think we can just delete everything in docs
Clonkk marked this conversation as resolved.
Show resolved Hide resolved
rmDir("docs")
mkDir("docs")

# todo: it should remove all files and directories not tracked in git from docs
for file in walkDirRec("docs"):
if file.endsWith(".html"):
rmFile(file)
echo "removed ", file
for file in ["book/book.json"]: # hardcoded files to remove (one for now)
if fileExists(file):
rmFile(file)
echo "removed ", file
# if by mistake I create html in book folder, remove them
for file in walkDirRec("book"):
if file.endsWith(".html"):
rmFile(file)
echo "removed ", file
# for file in walkDirRec("docs"):
# if file.endsWith(".html"):
# rmFile(file)
# echo "removed ", file
# for file in ["book/book.json"]: # hardcoded files to remove (one for now)
# if fileExists(file):
# rmFile(file)
# echo "removed ", file
# # if by mistake I create html in book folder, remove them
# for file in walkDirRec("book"):
# if file.endsWith(".html"):
# rmFile(file)
# echo "removed ", file


task srcpretty, "run nimpretty on nim files in src folder":
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/nimibook/books.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import std / os
import nimibook / [types, entries]
import nimibook / [types, entries]
import jsony

# fix for jsony: quote in string. https://github.com/treeform/jsony/issues/14
Expand Down
2 changes: 1 addition & 1 deletion src/nimibook/defaults.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ proc setDefaults*(book: var Book) =
book.preferred_dark_theme = "navy"
book.theme_option = {"light": "Light (default)", "rust": "Rust", "coal": "Coal", "navy": "Navy", "ayu": "Ayu"}.toTable
book.favicon_escaped = """<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2280%22>🐳</text></svg>">"""
book.git_repository_icon = "fa-github"
book.git_repository_icon = "fa-github"
7 changes: 2 additions & 5 deletions src/nimibook/docs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ proc useNimibook*(nbDoc: var NbDoc) =
# debugEcho "Current directory: ", getCurrentDir()
# debugEcho "Output file: ", nbDoc.filename


# templates are in nbSrcDir
nbDoc.templateDirs = @[nbSrcDir.string]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

templates are staying in book folder? I thought we were moving them to a templates but maybe that was an assumption I made in my head and never shared... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we misunderstood each other. My idea was to have a ressources/template folder in src/nimibook to deploy the mustache files automatically in the book folder (per the init mechanism we discussed)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this comment I describe an alternative folder structure. Do you think it could be done in this PR? if not we can do it/discuss it later. If it stays like this maybe I would just change ressources to resources :)

Copy link
Contributor Author

@Clonkk Clonkk Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on general folder structure, I was thinking, maybe we could put in src/nimibook a theme folder which contains a full example structure of a default nimibook (with folders docs\assets, templates, book, ...). If we add to that a clever config.nims (with a path ../../ we probably can also run nbook there and test the default structure during development). The theme folder is then the reference from where we populate assets.

If I understand correctly, you want to have the whole book structure in src/nimibook/theme and copy it in the current folder upon calling the init / update step ?

That is perfectly do-able, I don't think we even need a config.nims to test it (Init should do the trick). We can just copy "*.mustache" from templates into rootfolder (currentlybook comes from user input so we can't use it in theme).

Just one question : why keep docs/assets instead of just æssets copied into docs ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do and discuss this in another PR :)

nbDoc.context["title"] = nbDoc.context["here_path"]

# load book object
var book : Book
let bookPath = "../book/book.json"
if not bookPath.fileExists:
withDir("..".AbsoluteDir): # todo: add a withDir for RelativeDir in nimib /paths
discard execShellCmd("nimble dumpbook")
var book = load(bookPath)
book = load(bookPath)

# book configuration
nbDoc.context["language"] = book.language
Expand Down
2 changes: 1 addition & 1 deletion src/nimibook/entries.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import std / [os, strutils, strformat]
Clonkk marked this conversation as resolved.
Show resolved Hide resolved
import std / [os, strformat]
import nimibook / types

proc url*(e: Entry): string =
Expand Down
5 changes: 2 additions & 3 deletions src/nimibook/publishers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import nimib
proc nimPublish*(entry: Entry) =
let
cmd = "nim"
args = ["r", "-d:release", entry.path]
args = ["r", "-d:release", "-f", entry.path]
debugEcho "[Executing] ", cmd, " ", args.join(" ")
if execShellCmd(cmd & " " & args.join(" ")) != 0:
quit(1)
Expand All @@ -29,8 +29,7 @@ proc publish*(entry: Entry) =
raise newException(IOError, "Error invalid file extension.")

proc publish*(book: Book) =
dump book
for entry in book.toc.entries:
entry.publish()
clean book
# clean book
check book
21 changes: 16 additions & 5 deletions src/nimibook/tocs.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import std / [os, strformat]
import std / [os, strformat, macros]
import nimibook / [types, defaults, paths]

proc inc(levels: var seq[int]) =
Expand All @@ -11,15 +11,24 @@ proc add(toc: var Toc, entry: Entry) =
raise newException(IOError, fmt"Error entry {fullpath} doesn't exist.")
toc.entries.add entry

template initBook*() =
let
src = currentSourcePath().parentDir() / "assets"
target = getProjectPath() / "docs" / "assets"
# debugEcho "==> copyDir(", src, ", ", target, ")"
if dirExists(target):
removeDir(target)
createDir(target)
copyDir(src, target)

template newBookFromToc*(booklabel: string, rootfolder: string, body: untyped): Book =
var book = Book(book_title: booklabel)
book.setDefaults

var toc = Toc(path: rootfolder)
var levels: seq[int] = @[1]
var folders: seq[string] = @[rootfolder]

template entry(label, rfile: string, numbered=true) =
template entry(label, rfile: string, numbered = true) =
# debugEcho "==> entry <=="
# debugEcho " file>", rfile
let inputs = rfile.splitFile
Expand All @@ -30,7 +39,7 @@ template newBookFromToc*(booklabel: string, rootfolder: string, body: untyped):
if numbered:
inc levels

template draft(label, rfile: string) = entry(label, rfile, numbered=false)
template draft(label, rfile: string) = entry(label, rfile, numbered = false)

template section(label, rfile: string, sectionBody: untyped) =
let inputs = rfile.splitFile
Expand All @@ -49,4 +58,6 @@ template newBookFromToc*(booklabel: string, rootfolder: string, body: untyped):

body
book.toc = toc
book
# Dump json here so we avoid having to use Nimble in use Nimibook
dump(book)
book
6 changes: 3 additions & 3 deletions src/nimibook/types.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tables
import std / tables
export tables

type
Expand All @@ -22,7 +22,7 @@ type
#
# required fields (in the sense the mustache template will work bad if they are not present):
book_title*: string ## Title of the book as specified in `newBookFromToc`
# chapter_title: not needed?
# chapter_title: not needed?
title*: string # title of the page (what appears in browser tab); default in mdbook is "<chapter_title> - <book_title>" where chapter_title comes from toc
language*: string ## The main language of the book, which is used as a language attribute `<html lang="en">` for example (defaults to en)
description*: string ## A description for the book, which is added as meta information in the html <head> of each page
Expand Down Expand Up @@ -76,4 +76,4 @@ list of assets required as mentioned directly in document.mustache (other assets
- highlight.js
- book.js

]#
]#