diff --git a/.travis.yml b/.travis.yml index 07cde5164..cf071dbc3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,14 +15,3 @@ notifications: after_success: # push coverage results to Codecov - julia -e 'using Pkg; pkg"add Coverage"; using Coverage; Codecov.submit(Codecov.process_folder())' - -jobs: - include: - - stage: "Documentation" - julia: 1.2 - os: linux - script: - - julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); - Pkg.instantiate()' - - julia --project=docs/ docs/make.jl - after_success: skip diff --git a/README.md b/README.md index ff1e16d74..a9eabfb8f 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,52 @@ -# JuDoc - -| | [MacOS/Linux] | Windows | Coverage | Documentation | -| :---: | :-----------: | :-----: | :------: | :-----------: | -| ![Life cycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg) | [![Build Status](https://travis-ci.org/tlienart/JuDoc.jl.svg?branch=master)](https://travis-ci.org/tlienart/JuDoc.jl) | [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/tlienart/JuDoc.jl?branch=master&svg=true)](https://ci.appveyor.com/project/tlienart/JuDoc-jl) | [![codecov.io](http://codecov.io/github/tlienart/JuDoc.jl/coverage.svg?branch=master)](http://codecov.io/github/tlienart/JuDoc.jl?branch=master) | [![](https://img.shields.io/badge/docs-stable-blue.svg)](https://tlienart.github.io/JuDoc.jl/stable) [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://tlienart.github.io/JuDoc.jl/dev) | +
Marine iguanas are truly splendid creatures.
-Evolution is cool.
- -dot(a, a) = 14
-```
-
-and will look like
-
-```
-dot(a, a) = 14
-```
-
-If you now change the vector `a` in the code block, the page will be re-compiled with the code-block re-evaluated and the new output will be shown.
-
-If you would like the output to appear as text (not a code block), you can use `\textoutput` instead.
-Here's an example:
-
-`````judoc
-```julia:./code_pg1/ex2
-using Statistics
-temps = (15, 15, 14, 16, 18, 19, 20, 12, 10, 24)
-println("The _average_ temperature is **$(mean(temps))°C**.")
-```
-\textoutput{./code_pg1/ex2}
-`````
-
-Which will appear as:
-
-```julia
-using Statistics
-temps = (15, 15, 14, 16, 18, 19, 20, 12, 10, 24)
-println("The _average_ temperature is **$(mean(temps))°C**.")
-```
-
-The _average_ temperature is **16.3°C**.
-
-#### Hiding lines
-
-Sometimes you may want to run some lines but hide them from the presentation, for this just use `# hide` at the end of the line (`hide` is not case sensitive so `# HiDe` would be fine too):
-
-`````judoc
-```julia:./code_pg1/ex1
-using LinearAlgebra # hide
-a = [1, 2, 3]
-@show dot(a, a)
-```
-`````
-
-You could also hide the entire code block if you only care about the output, for this put a `# hideall` on any line:
-
-`````judoc
-```julia:./code_pg1/ex2
-#hideall
-using Statistics
-temps = (15, 15, 14, 16, 18, 19, 20, 12, 10, 24)
-println("The _average_ temperature is **$(mean(temps))°C**.")
-```
-\textoutput{./code_pg1/ex2}
-`````
-
-Which will appear as just:
-
-The _average_ temperature is **16.3°C**.
-
-### Separate evaluation
-
-The philosophy here is:
-
-* keep your code snippets in appropriate subfolders of `/assets/` where they can be run and their output can be saved, this can be compared to a `test/` folder in a Julia package,
-* run some or all of the snippets (before running JuDoc),
-* use `\input{...}{...}` in your markdown (see below) and when the website is updated, it will plug-in the most recent parts that have been generated.
-
-That way, if you modify the code, everything will be updated on the website too while ensuring that the code actually runs and generates the output you're displaying.
-
-Again, the script files can contain `# hide` at the end of lines you do not want to show.
-
-The `generate_results.jl` file should run the scripts and redirect outputs to the `assets/[path]/output` directory.
-You can use something like the script below (if you generate an example website with [`newsite`](@ref), it's already in there) though you can of course modify it as you wish.
-
-```julia
-dir = @__DIR__
-"""
- genplain(s)
-
-Small helper function to run some code and redirect the output (stdout) to a file.
-"""
-function genplain(s::String)
- open(joinpath(dir, "output", "$(splitext(s)[1]).out"), "w") do outf
- redirect_stdout(outf) do
- include(joinpath(dir, s))
- end
- end
-end
-# run `script1.jl` and redirect what it prints to `output/script1.out`
-genplain("script1.jl")
-# run `script2.jl` which has a savefig(joinpath(@__DIR__, "output", "script2.png"))
-include("script2.jl")
-```
-
-The function `genplain("scriptname.jl")` just redirects the output of the script to `output/scriptname.out`.
-So for instance if you have in `assets/scripts/script1.jl`
-
-```julia
-print("hello")
-```
-
-Then `genplain("script1.jl")` will generate `/assets/scripts/output/script1.out` with content
-
-```julia
-hello
-```
-
-!!! note
-
- You could have scripts in any language here (`R`, `Python`, ...) as long as the folder structure is the same.
-
-#### Inserting code
-
-In order to insert the code of a script and have it highlighted you can use
-
-```judoc
-\input{julia}{scripts/script1.jl}
-```
-
-or `\input{code:julia}{scripts/script1.jl}`. This will insert the content of the file `/assets/scripts/script1.jl` (see also the section earlier on paths) into a block that will be highlighted as julia code.
-
-#### Plain-text output
-
-In order to insert the plain-text output of a script, you can use
-
-```judoc
-\input{output}{scripts/script1.jl}
-```
-
-or `\input{output:plain}{scripts/script1.jl}`. This will insert the content of the file `/assets/scripts/script1.out` into a non-highlighted code-block.
-
-#### Plot output
-
-In order to insert a plot generated by a script, you can use
-
-```judoc
-\input{plot}{scripts/script1.jl}
-```
-
-or `\input{plot:id}{scripts/script1.jl}`. This will look for an image file with root name `/assets/scripts/script1.ext` where `ext` is `gif, png, jp(e)g, svg`.
-If you use `plot:id` then it will look for an image file with root name `/assets/scripts/script1id.ext`.
-
-The `plot:id` option is useful if you have a script that generates several plots for instance.
-
-#### Slicing up
-
-The structure in the `generate_results.jl` effectively means that all your code is run as one big script.
-This also means that if you want to slice some of your code in several parts and show intermediate outputs (e.g. plots), well you can just do that by having a `script_1_p1.jl`, `script_1_p2.jl` etc. and then just use `\input` multiple times.
-
-## File insertions
-
-A few commands are defined to help you with insertions of content; you can also define your own commands using custom HTML as was discussed before.
-
-### Inserting a figure
-
-The commands
-* `\figalt{alt}{path}`, and
-* `\fig{path}`
-are convenient commands to insert figures.
-Of course you're free to use the default markdown way `![alt](full_path)` instead.
-One difference with these commands though is that they allow the use of relative paths (see [the point on paths](#More-on-paths-1)); this can be convenient in order to organise your assets as you organise your pages.
-
-**Note**: as sometimes figures are generated by code, it is sometimes convenient to save them in a `path/output/` subfolder.
-The `\fig` and `\figalt` will try to look both in `path` and `path/output` so that you don't have to think about it.
-Likewise, if the extension is not provided, JuDoc will try common ones.
-For instance, all of these will work:
-
-`````judoc
-```julia:./ex1
-using PyPlot
-figure()
-plot([0, 1], [0, 1])
-savefig(joinpath(@__DIR__, "output", "test.png"))
-```
-\fig{./test}
-\fig{./output/test}
-\fig{./test.png}
-`````
-
-### Linking a file
-
-The command
-* `\file{name}{path}`
-is a convenient way to link to a local asset (e.g. a pdf file).
-Again, you could use the default markdown way `[name](full_path)` but, as for the fig commands, this allows the use of relative paths.
-
-### Inserting markdown
-
-In some situation, you may have some markdown in a file which you may want to include somewhere else.
-This can be achieved thanks to the `\textinput{path}` commmand.
-The path specification is as the other commands, and the text will be formatted.
-
-As an example you could have in `/assets/ccc/sidefile.md`:
-
-```judoc
-some **markdown** in a side file.
-```
-
-where in `/src/index.md`:
-
-```judoc
-This is the index then \textinput{ccc/sidefile}
-```
-
-and this will be equivalent to just having in `/src/index.md`:
-
-```judoc
-This is the index then some **markdown** in a side file.
-```
-
-**Note**: if you don't specify a file extension, `.md` is appended to the specified path.
-
-### Inserting a table
-
-You can insert tables directly from CSV files with the `\tableinput{header}{path}` command.
-If you generate the file on-the-fly, you should follow this example:
-`````judoc
-```julia:./tableinput/gen
-testcsv = "h1,h2,h3
-152,some string, 1.5f0
-0,another string,2.87"
-write("assets/pages/tableinput/testcsv.csv", testcsv)
-```
-`````
-Then you can insert the table with:
-`````judoc
-\tableinput{}{./tableinput/testcsv.csv}
-`````
-Which will result in:
-
-| h1 | h2 | h3 |
-| --- | -------------- | ----- |
-| 152 | some string | 1.5f0 |
-| 0 | another string | 2.87 |
-In this case given no header was specified in the call, a header was generated from the first line in the CSV (here: h1, h2, h3).
-
-If your file doesn't have a header, you can specify it in the call:
-`````judoc
-```julia:./tableinput/gen
-testcsv = "152,some string, 1.5f0
-0,another string,2.87"
-write("assets/pages/tableinput/testcsv2.csv", testcsv)
-
-\tableinput{custom h1,custom h2,custom h3}{./tableinput/testcsv2.csv}
-`````
-
-| custom h1 | custom h2 | custom h3 |
-| --------- | -------------- | --------- |
-| 152 | some string | 1.5f0 |
-| 0 | another string | 2.87 |
-
-With the above in mind, you can also include existing CSV files.
-
-!!! note
-
- The look of the table will be defined by your CSS stylesheet.
-
-There's a couple of rules that you have to keep in mind when using the `\tableinput{}{}` command:
-
-* Columns must be separated by a comma (`,`).
-* If a header is specified, its length must match the number of columns in the file.
-
-## Page variables
-
-Page variables are a way to interact with the HTML templating.
-In essence, you can define variables in the markdown which can then be called or used in the HTML building blocks that are in `src/_html_parts/`.
-
-!!! note
-
- Page variables are still somewhat rudimentary and while the syntax for declaring a variable will likely not change, the way they are used will almost certainly be refined in the future (see also [Templating](@ref)).
-
-### Local page variables
-
-The syntax to define a page variable in markdown is to write on a new line:
-
-```judoc
-@def variable_name = ...
-```
-
-where whatever is after the `=` sign should be a valid Julia expression (Julia will try to parse it and will throw an error if it can't).
-Multiline definitions are not (yet) allowed but if you have a need for that, please open an issue.
-The idea is that these variables are likely to be rather simple: strings, bools, ints, dates, ...
-I don't yet see a usecase for more involved things.
-
-Once such a variable is defined you can use it with the templating syntax (see [Templating](@ref)).
-For instance in your `src/index.md` you could have
-
-```judoc
-@def contributors = "Chuck Norris"
-```
-
-and in your `src/_html_parts/head.html` you could have
-
-```html
-{{isdef contributors}}
-This page was written with the help of {{fill contributors}}
-{{end}}
-```
-
-since `contributors` is a _local page variable_ that is defined in `src/index.md`, the corresponding `index.html` will show "_This page was written with the help of Chuck Norris_"; however on any other page, this will not show (unless, again, you define `@def contributors = ...` there).
-See also [Templating](@ref) for how page variables can be used in the HTML.
-
-#### Default variables
-
-A few variables are already present and used in the basic templates (you can still modify their value though it has to match the type):
-
-| Name | Accepted types | Default value | Function |
-| :-------- | :------------- | :------------ | :------- |
-| `title` | `Nothing`, `String` | `nothing` | title of the page (tab name)
-| `hasmath` | `Bool` | `true` | if `true` the KaTeX stylesheet and script will be added to the page
-| `hascode` | `Bool` | `false` | if `false` the highlight stylesheet and script will be added to the page
-| `date` | `String`, `Date`, `Nothing` | `Date(1)` | a date variable
-| `lang` | `String` | `"julia"` | the default language to use for code blocks
-| `reflinks`| `Bool` | `true` | whether there may be referred links like like `[link][id]` and `[id]: some/url`, turn this to false if your code has patterns like `[...]: ...` which are **not** link definitions (see also [quirks](#Quirks-1))
-
-Then there are some variables that are automatically assigned and that you should therefore **not** assign yourself (but you can use them):
-
-| Name | Type | Value | Function |
-| :--- | :------------- | :------------ | :------- |
-| `jd_ctime` | `Date` | `stat(file).ctime` | page creation date
-| `jd_mtime` | `Date` | `stat(file).mtime` | last page modification date
-
-
-### Global page variables
-
-You can also define _global page variables_ by simply putting the definition in the `src/config.md` file.
-For instance you may want to have a single main author across all pages and would then write
-
-```judoc
-@def author = "Septimia Zenobia"
-```
-
-in the `src/config.md` file.
-
-You can overwrite global variables in any page by redefining it locally.
-For instance you could set `hasmath` globally to `false` and `hascode` globally to `true` and then modify it locally as appropriate.
-
-There are also a few pre-defined global variables:
-
-| Name | Accepted types | Default value | Function |
-| :------------ | :------------- | :------------ | :------- |
-| `author` | `String`, `Nothing` | `THE AUTHOR` | author (e.g. may appear in footer)
-| `date_format` | `String` | `U dd, yyyy` | a valid date format specifier
-| `prepath` | `String` | "" | if the website is meant to be a _project_ website on GitHub for instance corresponding to a repo `github.com/username/repo` as opposed to `github.com/username.github.io`, then all url paths should be prepended with `repo/` which you can do by specifying `@def prepath = "repo"` (see also [hosting the website as a project website](/man/workflow/#Hosting-the-website-as-a-project-website-1))|
diff --git a/docs/src/man/templating.md b/docs/src/man/templating.md
deleted file mode 100644
index 7b5fdbd57..000000000
--- a/docs/src/man/templating.md
+++ /dev/null
@@ -1,173 +0,0 @@
-# Templating
-
-This page is about the templating syntax that is used in JuDoc which allows you to have some control over the generated HTML.
-It can be useful as a way to, depending on the page,
-
-* adjust the layout,
-* specify elements that should be inserted in the page such as date of last modification, page author(s), etc.,
-* specify auxiliary elements that should be loaded with the page such as stylesheets or javascript libraries,
-* ...
-
-!!! note
-
- The templating system is still rudimentary at this point and is likely to be significantly improved over time (your help and suggestions are welcome!).
-
-**Contents**:
-
-* [Basic syntax](#Basic-syntax-1)
-* [Conditional blocks](#Conditional-blocks-1)
- * [Base conditional blocks](#Base-conditional-blocks-1)
- * [`isdef` conditional blocks](#isdef-conditional-blocks-1)
- * [`ispage` conditional blocks](#ispage-conditional-blocks-1)
-* [Function blocks](#Function-blocks-1)
-
-## Basic syntax
-
-When developing your website, you can define global or local page variables using
-
-```judoc
-@def varname = ...
-```
-
-either in the `src/config.md` file (in which case the variable is global) or in a specific page (in which case the variable is local or overwrites a global one).
-See also the page on the markdown [Syntax](@ref).
-
-These variables can subsequently be called in "HTML Blocks" in a way that is inspired from Hugo's templating system via `{{...}}`.
-These blocks would be placed in the HTML layout building blocks files that are in `src/_html_parts/`.
-
-A simple example is the insertion of a string defining the title of the page (which would appear the tab name).
-In the markdown of `src/path/page1.md` you would have:
-
-```judoc
-@def title = "Title for page 1"
-```
-
-and in `src/_html_parts/head.html` you would have
-
-```html
-- | - - - - - - -
- CONTENT HERE - - |
-
- | - - - - - - -- - -``` - -and the `foot.html` should be adapted to: - -```html - - | -
` blocks - -#### Fixing spacing - -Firefox or Chrome/ium's excellent dev-tools are super helpful to fine tune stylesheets. -Here things are pretty straightforward though. - -Firstly we need to add vertical padding above `` level title: - -```css -h1 { padding-top: 2em; } -``` - -Then, let's widen the menu a little - -```css -td#layout-menu { - padding-left: 15px; - padding-right: 25px; -} -``` - -and let's reduce the padding on the left of the `jd-content` element: - -```css -.jd-content { padding-left: 5%; } -``` - -Thirdly, in the original stylesheet there is this element: - -```css -pre { - padding: 0; - margin: 0; -} -``` - -which you can just remove to have a bit more space around code blocks. - -There's probably still things that could be done to improve the layout overall (and make it more responsive!) but we'll leave it at that. - -![](../assets/jemdoc4.png) - -### Adjusting other files - -Here we don't need to adjust anything else but you could want to adjust the pages in another context: - -* `head_highlight`, `head_katex`, `foot_highlight` and `foot_katex` are probably best left as they are, they will be appended if need be to pages (see in `head` and `foot` the `{{if hasmath}}` and `{{if hascode}}` blocks) -* `page_foot` you may want to change, it defines what goes at the bottom of the `.jd-content` div. - -By default `page_foot` looks like - -```html -
--``` - -It should be fairly straightforward to adapt that to your needs. - -## Making a PR to the theme repo - -Let's say you've built your own template and are pretty happy with the result and you'd like to share it for other users, great! thanks for being a good citizen. - -### Create a new folder - -Head to the [JuDocTemplates.jl](https://github.com/tlienart/JuDocTemplates.jl) repository and make a PR. -The key is to keep track of what you've modified and what was left as before so that the repo is not cluttered with copies of the same file. - -In the example above the following files were changed: - -* `head.html` and `foot.html`, -* `jemdoc.css` the stylesheet. - -The JuDocTemplates repository automatically fills in the gap so you just have to provide the files that have changed. -Imitate the structure corresponding to [`basic`](https://github.com/tlienart/JuDocTemplates.jl/tree/master/src/templates/basic/src): - -``` -. -└── src - ├── _css - │ └── basic.css - └── _html_parts - └── head.html -``` - -So in the case of `jemdoc`, I will create a new folder `jemdoc` in `src/templates/` with - -``` -. -└── src - ├── _css - │ └── jemdoc.css - └── _html_parts - ├── foot.html - └── head.html -``` - -### Add your template to the list - -Next, you need to indicate the new template in `JuDocTemplates.jl` by simply adding it to the `LIST_OF_TEMPLATES` constant. - -Then, you need to add a description for your template in `docs/make.jl` (please respect the alphabetical order): - -```julia -"jemdoc" => """ - jemdoc -- © {{ fill author }}. Last modified: {{ fill jd_mtime }}. Website built with JuDoc.jl. --Simple theme with a side navigation bar, no extra javascript and a simple stylesheet. (Adapted from the original Jemdoc theme.)
- """, -``` - -Lastly you need to take a screenshot of what the template looks like of size 480x480, put it in `docs/thumb` and adjust `docs/index_head.html` following the example of the other templates: - -```css -#jemdoc { - background: url("thumb/jemdoc.png"); - background-size: contain; -} -``` - -### Check that things work - -Finally, you need to check that everything works (which is the first thing I'll do when reviewing your PR). -For that: first run the file `docs/make.jl`; this will generate a website in `docs/build` then using for instance [`LiveServer.jl`](https://github.com/asprionj/LiveServer.jl), check the generated website and that the demo corresponding to your template works as expected. - -And that's it! thanks a lot! diff --git a/docs/src/man/troubleshooting.md b/docs/src/man/troubleshooting.md deleted file mode 100644 index 695565e32..000000000 --- a/docs/src/man/troubleshooting.md +++ /dev/null @@ -1,56 +0,0 @@ -# Troubleshooting - -This page is about some of the known errors you may encounter when using JuDoc and how to deal with them. -If you encounter an error that is not mentioned here, then it's probably a bug and it would be great if you could open an issue! - -* [Error on interruption](#Error-on-interruption-1) -* [IOStream error](#IOStream-error-1) - - -## Error on interruption - -You may (rarely) get an an error thrown at you when interrupting the server with `+C`, particularly when using Juno. -There are a couple of reasons this may happen, both unrelated to JuDoc. - -### Juno - -Juno (very rarely) crashes if you coincidentally press ` +C` while Juno is doing something in the background (Juno issue [#309](https://github.com/JunoLab/Juno.jl/issues/309)). - -The stacktrace you will see will seem particularly obscure, for instance: - -``` -InterruptException: -_string_n at string.jl:60 [inlined] -StringVector at iobuffer.jl:31 [inlined] -#IOBuffer#320(::Bool, ::Bool, ::Nothing, ::Bool, ::Int64, ::Int64, ::Type{Base.GenericIOBuffer{Array{UInt8,1}}}) at iobuffer.jl:114 -(...) -``` - -or - -``` -julia> "miniERROR: InterruptException: -Stacktrace: - [1] poptaskref(::Base.InvasiveLinkedListSynchronized{Task}) at ./task.jl:564 - [2] wait() at ./task.jl:591 -(...) -``` - -**Solution**: ignore the error, restart Julia. - -### Not-Juno - -The [`LiveServer.jl`](https://github.com/asprionj/LiveServer.jl) package, which handles the live-serving of the files, is based upon [`HTTP.jl`](https://github.com/asprionj/LiveServer.jl). -The latter has a fairly complex codebase with a number of asynchronous tasks and is known to sometimes crash in (somewhat) mysterious ways. - -If the stacktrace mentions `uv_write`, `uv_write_async`, `libuv` or something of the sorts, then this is it. - -Like the "Juno" case, these errors are caused when you happen to press interrupt just as the package was doing something important in the background. -This is very rare but can happen and you can safely ignore it. - -**Solution**: ignore the error, restart Julia. - - -## IOStream error - -See the comment about HTTP.jl in the [subsection above](#Not-Juno-1). diff --git a/docs/src/man/workflow.md b/docs/src/man/workflow.md deleted file mode 100644 index d0d064b7c..000000000 --- a/docs/src/man/workflow.md +++ /dev/null @@ -1,409 +0,0 @@ -# Workflow - -In this section it is assumed that you will eventually host your website on GitHub or GitLab but it shouldn't be hard to adapt to your particular case if you intend to self-host or use another service. - -**Contents**: - -* [Local editing](#Local-editing-1) - * [Folder structure](#Folder-structure-1) -* [Libraries](#Libraries-1) - * [Highlight](#Highlight-1) -* [Hosting the website](#Hosting-the-website-1) - * [Hosting the website as a project website](#Hosting-the-website-as-a-project-website-1) -* [Optimisation step](#Optimisation-step-1) -* [(git) synchronisation](#(git)-synchronisation-1) - * [Merge conflicts](#Merge-conflicts-1) -* [Using Literate.jl](#Using-Literate.jl-1) - -## Local editing - -To get started, the easiest is to use the [`newsite`](@ref) function to generate a website folder which you can then modify to your heart's content. -The command takes one mandatory argument: the name of the folder, and you can specify a template with `template=...`: - -```julia-repl -julia> newsite("Test"; template="pure-sm") -✓ Website folder generated at Test (now the current directory). -→ Use `serve()` from `JuDoc` to see the website in your browser. -``` - -```@raw html -Click here for a demo of the supported templates (opens in a new tab). -``` - -Once you have created a new site with the template of your choice and are in the corresponding folder (`newsite` will `cd` to the new folder) you can serve your website with - -```julia-repl -julia> serve() -✓ LiveServer listening on http://localhost:8000/ ... - (use CTRL+C to shut down) -``` - -and navigate in a browser to the corresponding address to see the website being rendered. - -!!! note - - If you're using the Atom editor, you may like to use the _Atom browser_ extension which allows you to have a browser in an Atom pane. - -### Folder structure - -The [`newsite`](@ref) command above generates folders and examples files following the appropriate structure, so the easiest is to start with that and modify in place. -The main folders (generated by `newsite`) are: - -``` -. -├── assets/ -├── libs/ -└── src/ -``` - -Once you run [`serve`](@ref) the first time, two additional folders are generated (`css/` and `pub/`) along with the landing page `index.html`. - -Among these folders, - -* the **main folder** is `src/` and its subfolders, this is effectively where the source for your site is, -* you should _ignore_ `css/` and `pub/` these are _generated_ and any changes you'd do there will be silently over-written whenever you modify files in `src/`; the same comment holds for `index.html`, -* the folders `assets/` and `libs/` contain _auxiliary items_ that are useful for your site: `assets/` would contain code snippets, images etc. while `libs/` would contain javascript libraries that you may need (KaTeX and highlight are in there by default). - -In the `src/` folder, the structure is: - -``` -. -├── _css -│ ├── judoc.css -│ └── ... -├── _html_parts -│ ├── foot.html -│ ├── head.html -│ └── ... -├── config.md -├── index.md -└── pages - ├── page1.md - └── ... -``` - -**Pages** - -The `index.md` will generate the site's landing page. -The `pages/page1.md` would correspond to pages on your website (you can have whatever subfolder structure you want in there, and will just have to adapt internal links appropriately). -See also the [Syntax](@ref). - -!!! note - - At any point you can write pages in HTML from scratch if you want to go beyond what JuDoc can offer; these pages will just be copied as they are. - So for instance you may prefer to write an `index.html` file instead of using the `index.md` to generate it. - You would still put it at the exact same place though (`src/index.html`) and let JuDoc copy the files at the appropriate place. - -**HTML parts** - -The files in `_html_parts/` are the building blocks that will go around the (processed) content contained in the `*.md` pages. -So the `head.html` will be inserted before, the `foot.html` after etc. -Adjusting these will help you make sure the site has the exact layout you want. -The layout can also depend on the page you're on if it uses `{{ispage path/to/page}} ... {{end}}` (see [Templating](@ref)). - -**CSS** - -The style sheets in `_css/` will help you tune the way your site looks. -The `judoc.css` is the stylesheet that corresponds more specifically to the styling of the `.jd-content` div and all that goes in it, it is usually the first style-sheet that should be loaded. -The simplest way to adjust the style easily would be to define your own stylesheet `_css/adjustments.css` and it be the last stylesheet loaded in `_html_parts/head.html` so that you can easily overwrite whatever properties you don't like and define your own. -You could also have specific stylesheet that would only be loaded on specific pages using `{{ispages ...}}` (see [Templating](@ref)). - -!!! note - - It wouldn't be hard for JuDoc to use page variables in the CSS stylesheet too. You could then do things like - ```judoc - @def col1 = aliceblue - ``` - and - ```css - .mydiv { color: $col1 } - ``` - I'm not 100% sure how useful that could be though so if you would like to see this happen, please open an issue! - -**Folder organisation** - -Auxiliary assets such as images, code snippets, pdfs etc. should ideally go in the `assets/` folder (or subfolders). -The files that are in `assets/` will not tracked for change and will also not get copied around. - -An alternative approach is to keep auxiliary assets in `src/pages/` (or subfolders). -The main advantage being that some users might find it better to structure their content with the page markdown as well as the page resources in one folder. -If you decide to do this, bear in mind that whatever is in `src/pages/` gets copied to the generated `pub/` folder during the initial website compilation. -While this will be imperceptible if you only have a few light assets, it could slow the initial pass down if you have many heavy assets; if that's the case though, you are probably better off with the first approach putting all resources in `assets/` and subfolders. - -## Libraries - -Assuming you used the [`newsite`](@ref) function to get started, you have a `libs/` folder with - -``` -. -├── highlight/ -└── katex/ -``` - -If you require other libraries to run your website, this is where you should put them while not forgetting to load them in your `_html_parts`; for instance in the default `foot_highlight.html` you will find: - -```html - - -``` - -which loads and applies `highlight.js`. - -### Highlight - -Assuming you used the [`newsite`](@ref) function to get started, you have the `libs/highlight/` folder with - -``` -. -├── github.min.css -└── highlight.pack.js -``` - -If you want to change either how things look or which languages are supported, you should head to [highlightjs.org](https://highlightjs.org/download/), select the languages you want in the **Custom package** section, download the bundle and copy over the relevant files to `libs/highlight/`. -By default, the files that are created with [`newsite`](@ref) allow highlighting for `bash`, `html/xml`, `python`, `julia`, `julia-repl`, `css`, `r`, `markdown`, `ini/TOML`, `ruby` and `yaml`. - -Just remember to refer to the appropriate style-sheet in your HTML building blocks for instance the default `src/_html_parts/head_highlight.html` contains: - -```html - -``` - -## Hosting the website - -In this section, the assumption is that you will host your website on GitHub. -The procedure should be very similar with GitLab. -If you're using your own hosting, you would pretty much just need to copy/clone the content of your folder. - -On GitHub/GitLab, the first step is to create a repository that would be acceptable for a personal webpage. - -* Follow the guide to [do so on GitHub](https://pages.github.com/#user-site). -* Or the guide to [do so on GitLab](https://about.gitlab.com/product/pages/). - -Once the repository is created, clone it on your computer, remove whatever is in it if it wasn't empty and copy over the content of the website folder (so if you had done `newsite("Test/")` then you'd copy over the content of the folder `Test` into the newly cloned folder `username.github.io/`). - -Now just do the usual `git add`, `commit` and `push` and your site will be live in a matter of minutes. - -### Gitlab users - -On Gitlab, there are two small differences: - -1. your website needs to eventually be in a `public/` directory of the repository, -1. you need to specify a CI/CD script that tells Gitlab how to deploy the site. - -Luckily both of these can be done in one shot, all you need to do is add a script as follows in your repository: - -```yaml -pages: - stage: deploy - script: - - mkdir .public - - cp -r * .public - - mv .public public - artifacts: - paths: - - public - only: - - master -``` - -The only non-trivial bit is the `script:` section: the only thing it does is tell the runner to copy all your files in a `public/` "virtual" directory. -Note that this will _not_ physically create a directory in your repo, rather it will, on Gitlab, make sure the files are located in such a way that they can be rendered. - -**Note**: if for some reason your repository is private and you would like to avoid for some files to be in the `public/` folder, then just add a couple of lines in the `script:` part removing (`rm`) the files you don't want to put there (e.g. sensitive data files). - -### Hosting the website as a project website - -You may want to host your website not as a user website on `username.github.io/` but as a project website on `username.github.io/project/`. -For this to work well, the only thing that is required is to have all links start with `/project/` instead of just `/` (the default). -JuDoc makes this easy to do this as a final step before publication. - -The best way to do it is: - -1. specify a `prepath` global variable in your `src/config.md` file by adding a line: `@def prepath = "project"`, -1. use [`optimize`](@ref) and/or [`publish`](@ref) (even if you don't do the minification or the prerendering). - -Alternatively, you can specify the `prepath` when calling `optimize` or `publish` so for instance: - -```julia-repl -julia> optimize(prerender=false, minify=false, prepath="project") -``` - -will do a pass over all generated pages and make sure all paths are prepended with `/project/`. - -## Optimisation step - -The [`optimize`](@ref) function should typically be run before you push your website online. -That step can: - -1. pre-render KaTeX and highlight code to HTML so that the pages don't have to load these javascript libraries, -1. minify all generated HTML and CSS. - -Those steps (which you can opt out of using the appropriate keyword `prerender=false` or `minify=false`) may lead to faster loading pages. - -In order to run this optimisation step, you will need some [dependencies](/#External-dependencies-1) but if you don't have them, JuDoc will tell you and ignore the corresponding step. -Note also that doing a full pass of pre-rendering and minifying may take a few seconds depending on how many pages you have. - -## (git) synchronisation - -The [`publish`](@ref) function helps you wrap the [`optimize`](@ref) step as well as a git `add`, `commit` and `push` all in one (provided the `optimize` step didn't fail). - -So, in short, your full workflow may look like - -```julia -using JuDoc -# cd to the appropriate directory -cd("path/user.github.io") -# start serving -serve() -# ... -# edit things, add pages, tune layout etc. -# while keeping an eye on the browser to check -# ... -# all looks good, stop the server with CTRL+C -^C -# and now the final step to optimize and push: -publish() -``` - -### Merge conflicts - -Since the `pub/` and `css/` and `index.html` folder are _generated_, it can sometimes cause git merge conflicts if, for instance, you have edited your website on computer A, optimised and published it and then subsequently pulled on computer B where -- say -- the content hasn't been minified yet. -This could cause messy merge conflicts that would be annoying to fix. -An easy way to reduce this risk is to simply remove the generated folders and files before pulling. - -The function [`cleanpull`](@ref) does precisely that and should be used if you intend to edit your website from multiple computers. -It simply: - -1. removes all generate folders/files from your current director, -1. pulls. - -So in such a case, your full workflow would be: - -```julia -using JuDoc -cd("path/user.github.io") -cleanpull() -serve() -# ... -publish() -``` - -## Using Literate.jl - -(_Thanks to [@cormullion](https://github.com/cormullion) for this section_) - -You can use Fredrik Ekre's [Literate.jl](https://github.com/fredrikekre/Literate.jl) package to create Markdown pages suitable for including in your JuDoc workflow. Literate.jl lets you write everything in a Julia source file, including your code, comments, tests, generated plots, and so on. When you execute the Julia file, all your code runs, and you can arrange for Literate.jl to write output such as Markdown-formatted text (and/or Jupyter notebooks) to suitable files. -Literate.jl's syntax relies on various different flavours of comment, some of which are shown in the simple example below. - -All non-Julia code has to be commented. -Markdown markup language is applied immediately after the first `# `. -You can see the `>` Markdown quote syntax and the `##` Markdown header level 2 syntax. -Lines preceded by `#jl` are not included in the Markdown output. -Lines ending with `#src` are evaluated when you run the Julia file, but are not copied into the Markdown output file. -Lines beginning with `#src` are Julia comments that don't make it as far as the Markdown file. -Refer to [Literate.jl's docs](https://fredrikekre.github.io/Literate.jl/stable/) for more information. - -You can see from the final five lines in the example that, when you run this file in Julia, the final step is to run the `Literate.markdown` function, taking the name of the Julia source file (`functionoftheweek.jl`) as input, and writing a new Markdown file to the directory `src/pages/` as `fotw_floorceil.md`. -Finally, if the JuDoc server is running, you'll find the generated HTML page as `/pub/fotw_floorceil.html`. - -````` -#jl This is a Julia source file! - -# @def title = "Function of the week: floorceil()" -# @def hascode = true - -# > To be, or not to be. That's what they reckon. - -# ## Function of the week: floorceil() - -# Welcome to another weekly post in which I present a cool Julia function that I've -# just discovered. This week it's the turn of `floorceil()`. It might sound like -# something that comes in a tin, but in fact it's a useful function in the Dates module -# that returns two Dates or DateTimes, one before, and one after, the specified time by -# a certain unit of time. - -# For example: - -using Dates - -Dates.now() - -# -# 2019-05-09T11:29:23.913 -# -#src # would be nice if the output from commands could be included! - -Dates.floorceil(now(), Dates.Month(1)) - -# -# (2019-05-01T00:00:00, 2019-06-01T00:00:00) -# - -# and you can see that the result contains the beginning and the end of the month -# that includes the present time of day. - -a, b = (Dates.floorceil(now(), Dates.Month(1))); -Dates.canonicalize(Dates.CompoundPeriod(b - a)) - -# -# 4 weeks, 3 days -# - -# That's all for today. Until next time! - -#src Lines with this tag appear only in this Julia source file. -using Literate #src -Literate.markdown("functionoftheweek.jl", #src - "src/pages/", #src - name="fotw_floorceil", #src - documenter=false) #src - -````` - -When this Julia file is executed, the resulting Markdown output will look like the listing below. -Notice that the two JuDoc `@def` lines have survived the journey from Julia to Markdown intact, and will now be actively available for the JuDoc generation process. - -````` -@def title = "Function of the week: floorceil()" -@def hascode = true - -> To be, or not to be. That's what they reckon. - -## Function of the week: floorceil() - -Welcome to another weekly post in which I present a cool Julia function that I've -just discovered. This week it's the turn of `floorceil()`. It might sound like -something that comes in a tin, but in fact it's a useful function in the Dates module -that returns two Dates or DateTimes, one before, and one after, the specified time by -a certain unit of time. - -For example: - -```julia -using Dates - -Dates.now() -``` - -2019-05-09T11:29:23.913 - -```julia -Dates.floorceil(now(), Dates.Month(1)) -``` - -(2019-05-01T00:00:00, 2019-06-01T00:00:00) - -and you can see that the result contains the beginning and the end of the month -that includes the present time of day. - -```julia -a, b = (Dates.floorceil(now(), Dates.Month(1))); -Dates.canonicalize(Dates.CompoundPeriod(b - a)) -``` - -4 weeks, 3 days - -That's all for today. Until next time! - -*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).* -`````