-
Notifications
You must be signed in to change notification settings - Fork 0
/
Old_Index
385 lines (264 loc) · 14.8 KB
/
Old_Index
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
@def title = "Franklin Example"
@def tags = ["syntax", "code"]
# How to use Franklin
\tableofcontents <!-- you can use \toc as well -->
This section is meant as a refresher if you're new to Franklin.
Have a look at both how the website renders and the corresponding markdown (`index.md`).
Modify at will to get a feeling for how things work!
Ps: if you want to modify the header or footer or the general look of the website, adjust the files in
* `src/_css/` and
* `src/_html_parts/`.
## The base with Markdown
The [standard markdown syntax](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) can be used such as titles using `#`, lists:
* element with **bold**
* element with _emph_
or code-blocks `inline` or with highlighting (note the `@def hascode = true` in the source to allow [highlight.js](https://highlightjs.org/) to do its job):
```julia
abstract type Point end
struct PointR2{T<:Real} <: Point
x::T
y::T
end
struct PointR3{T<:Real} <: Point
x::T
y::T
z::T
end
function len(p::T) where T<:Point
sqrt(sum(getfield(p, η)^2 for η ∈ fieldnames(T)))
end
```
You can also quote stuff
> You must have chaos within you to ...
or have tables:
| English | Mandarin |
| --------------- | ---------- |
| winnie the pooh | 维尼熊 |
Note that you may have to do a bit of CSS-styling to get these elements to look the way you want them (the same holds for the whole page in fact).
### Symbols and html entities
If you want a dollar sign you have to escape it like so: \$, you can also use html entities like so: → or π or, if you're using Juno for instance, you can use `\pi[TAB]` to insert the symbol as is: π (it will be converted to a html entity).[^1]
If you want to show a backslash, just use it like so: \ ; if you want to force a line break, use a ` \\ ` like \\ so (this is on a new line).[^blah]
If you want to show a backtick, escape it like so: \` and if you want to show a tick in inline code use double backticks like ``so ` ...``.
Footnotes are nice too:
[^1]: this is the text for the first footnote, you can style all this looking at `.fndef` elements; note that the whole footnote definition is _expected to be on the same line_.
[^blah]: and this is a longer footnote with some blah from veggie ipsum: turnip greens yarrow ricebean rutabaga endive cauliflower sea lettuce kohlrabi amaranth water spinach avocado daikon napa cabbage asparagus winter purslane kale. Celery potato scallion desert raisin horseradish spinach carrot soko.
## Basic Franklin extensions
### Divs
It is sometimes useful to have a short way to make a part of the page belong to a div so that it can be styled separately.
You can do this easily with Franklin by using `@@divname ... @@`.
For instance, you could want a blue background behind some text.
@@colbox-blue
Here we go! (this is styled in the css sheet with name "colbox-blue").
@@
Since it's just a `<div>` block, you can put this construction wherever you like and locally style your text.
### LaTeX and Maths
Essentially three things are imitated from LaTeX
1. you can introduce definitions using `\newcommand`
1. you can use hyper-references with `\eqref`, `\cite`, ...
1. you can show nice maths (via KaTeX)
The definitions can be introduced in the page or in the `config.md` (in which case they're available everywhere as opposed to just in that page).
For instance, the commands `\scal` and `\R` are defined in the config file (see `src/config.md`) and can directly be used whereas the command `\E` is defined below (and therefore only available on this page):
\newcommand{\E}[1]{\mathbb E\left[#1\right]}
Now we can write something like
$$ \varphi(\E{X}) \le \E{\varphi(X)}. \label{equation blah} $$
since we've given it the label `\label{equation blah}`, we can refer it like so: \eqref{equation blah} which can be convenient for pages that are math-heavy.
In a similar vein you can cite references that would be at the bottom of the page: \citep{noether15, bezanson17}.
**Note**: the LaTeX commands you define can also incorporate standard markdown (though not in a math environment) so for instance let's define a silly `\bolditalic` command.
\newcommand{\bolditalic}[1]{_**!#1**_} <!--_ ignore this comment, it helps atom to not get confused by the trailing underscore when highlighting the code but is not necessary.-->
and use it \bolditalic{here for example}.
Here's another quick one, a command to change the color:
\newcommand{\col}[2]{~~~<span style="color:~~~#1~~~">~~~!#2~~~</span>~~~}
This is \col{blue}{in blue} or \col{#bf37bc}{in #bf37bc}.
### A quick note on whitespaces
For most commands you will use `#k` to refer to the $k$-th argument as in LaTeX.
In order to reduce headaches, this forcibly introduces a whitespace on the left of whatever is inserted which, usually, changes nothing visible (e.g. in a math settings).
However there _may be_ situations where you do not want this to happen and you know that the insertion will not clash with anything else.
In that case, you should simply use `!#k` which will not introduce that whitespace.
It's probably easier to see this in action:
\newcommand{\pathwith}[1]{`/usr/local/bin/#1`}
\newcommand{\pathwithout}[1]{`/usr/local/bin/!#1`}
* with: \pathwith{script.jl}, there's a whitespace you don't want 🚫
* without: \pathwithout{script.jl} here there isn't ✅
### Raw HTML
You can include raw HTML by just surrounding a block with `~~~`.
Not much more to add.
This may be useful for local custom layouts like having a photo next to a text in a specific way.
~~~
<div class="row">
<div class="container">
<img class="left" src="/assets/rndimg.jpg">
<p>
Marine iguanas are truly splendid creatures. They're found on the Gálapagos islands, have skin that basically acts as a solar panel, can swim and may have the ability to adapt their body size depending on whether there's food or not.
</p>
<p>
Evolution is cool.
</p>
<div style="clear: both"></div>
</div>
</div>
~~~
**Note 1**: again, entire such blocks can be made into latex-like commands via `\newcommand{\mynewblock}[1]{...}`.
**Note 2**: whatever is in a raw HTML block is *not* further processed (so you can't have LaTeX in there for instance). A partial way around this is to use `@@...` blocks which *will* be recursively parsed. The following code gives the same result as above with the small difference that there is LaTeX being processed in the inner div.
@@row
@@container
@@left ![](/assets/rndimg.jpg) @@
@@
Marine iguanas are **truly splendid** creatures. They're not found in equations like $\exp(-i\pi)+1$. But they're still quite cool.
~~~
<div style="clear: both"></div>
~~~
@@
## Pages and structure
Here are a few empty pages connecting to the menu links to show where files can go and the resulting paths. (It's probably best if you look at the source folder for this).
* [menu 1](/menu1/)
* [menu 2](/menu2/)
* [menu 3](/menu3/)
## References (not really)
* \biblabel{noether15}{Noether (1915)} **Noether**, Körper und Systeme rationaler Funktionen, 1915.
* \biblabel{bezanson17}{Bezanson et al. (2017)} **Bezanson**, **Edelman**, **Karpinski** and **Shah**, [Julia: a fresh approach to numerical computing](https://julialang.org/research/julia-fresh-approach-BEKS.pdf), SIAM review 2017.
## Header and Footer
As you can see here at the bottom of the page, there is a footer which you may want on all pages but for instance you may want the date of last modification to be displayed.
In a fashion heavily inspired by [Hugo](https://gohugo.io), you can write things like
```html
Last modified: {{ fill fd_mtime }}.
```
(cf. `src/_html_parts/page_foot.html`) which will then replace these braces with the content of a dictionary of variables at the key `fd_mtime`.
This dictionary of variables is accessed locally by pages through `@def varname = value` and globally through the `config.md` page via the same syntax.
There's a few other such functions of the form `{{fname p₁ p₂}}` as well as support for conditional blocks. If you wander through the `src/_html_parts/` folder and its content, you should be able to see those in action.
+++
title = "Code blocks"
hascode = true
date = Date(2019, 3, 22)
rss = "A short description of the page which would serve as **blurb** in a `RSS` feed; you can use basic markdown here but the whole description string must be a single line (not a multiline string). Like this one for instance. Keep in mind that styling is minimal in RSS so for instance don't expect maths or fancy styling to work; images should be ok though: ![](https://upload.wikimedia.org/wikipedia/en/3/32/Rick_and_Morty_opening_credits.jpeg)"
tags = ["syntax", "code"]
+++
# Working with code blocks
\toc
## Live evaluation of code blocks
If you would like to show code as well as what the code outputs, you only need to specify where the script corresponding to the code block will be saved.
Indeed, what happens is that the code block gets saved as a script which then gets executed.
This also allows for that block to not be re-executed every time you change something _else_ on the page.
Here's a simple example (change values in `a` to see the results being live updated):
```julia:./exdot.jl
using LinearAlgebra
a = [1, 2, 3, 3, 4, 5, 2, 2]
@show dot(a, a)
println(dot(a, a))
```
You can now show what this would look like:
\output{./exdot.jl}
**Notes**:
* you don't have to specify the `.jl` (see below),
* you do need to explicitly use print statements or `@show` for things to show, so just leaving a variable at the end like you would in the REPL will show nothing,
* only Julia code blocks are supported at the moment, there may be a support for scripting languages like `R` or `python` in the future,
* the way you specify the path is important; see [the docs](https://tlienart.github.io/franklindocs/code/index.html#more_on_paths) for more info. If you don't care about how things are structured in your `/assets/` folder, just use `./scriptname.jl`. If you want things to be grouped, use `./group/scriptname.jl`. For more involved uses, see the docs.
Lastly, it's important to realise that if you don't change the content of the code, then that code will only be executed _once_ even if you make multiple changes to the text around it.
Here's another example,
```julia:./code/ex2
for i ∈ 1:5, j ∈ 1:5
print(" ", rpad("*"^i,5), lpad("*"^(6-i),5), j==5 ? "\n" : " "^4)
end
```
which gives the (utterly useless):
\output{./code/ex2}
note the absence of `.jl`, it's inferred.
You can also hide lines (that will be executed nonetheless):
```julia:./code/ex3
using Random
Random.seed!(1) # hide
@show randn(2)
```
\output{./code/ex3}
## Including scripts
Another approach is to include the content of a script that has already been executed.
This can be an alternative to the description above if you'd like to only run the code once because it's particularly slow or because it's not Julia code.
For this you can use the `\input` command specifying which language it should be tagged as:
\input{julia}{/_assets/scripts/script1.jl} <!--_-->
these scripts can be run in such a way that their output is also saved to file, see `scripts/generate_results.jl` for instance, and you can then also input the results:
\output{/_assets/scripts/script1.jl} <!--_-->
which is convenient if you're presenting code.
**Note**: paths specification matters, see [the docs](https://tlienart.github.io/franklindocs/code/index.html#more_on_paths) for details.
Using this approach with the `generate_results.jl` file also makes sure that all the code on your website works and that all results match the code which makes maintenance easier.
+++
title = "Menu 3"
+++
# Working with tags
**Example**:
* page with tag [`syntax`](/tag/syntax/)
* page with tag [`image`](/tag/image/)
* page with tag [`code`](/tag/code/)
\toc
## Indicating tags
To mark a page with tags, add:
```markdown
+++
tags = ["tag1", "tag2"]
+++
```
then that page, along with all others that have the tag `tag1` will be listed at `/tag/tag1/`.
## Customising tag pages
You can change how a `/tag/...` page looks like by modifying the `_layout/tag.html`. An important note is that you can **only** use **global** page variables (defined in `config.md`).
There are three "exceptions":
1. you can still use `{{ispage /tag/tagname/}} ... {{end}}` (or `{{isnotpage ...}}`) to have a different layout depending on the tag,
1. you can use the `fd_tag` variable which contains the name of the tag so `{{fill fd_tag}}` will input the tag string as is,
1. you can use `{{fill varname path/to/page}}` to exploit a page variable defined in a specific page.
## Customising tag lists
By default the tag list is very simple: it just collects all pages that match the tags and it shows them in a simple list by anti-chronological order (more recent at the top).
You can customise this by defining your own `hfun_custom_taglist` function in the `utils.jl` file. The commented blueprint for the simple default setting is below and should give you an idea of how to write your own generator.
Assuming you've defined such a function, don't forget to use `{{custom_taglist}}` in the `_layout/tag.html` instead of the default `{{taglist}}`.
```julia
function hfun_custom_taglist()::String
# -----------------------------------------
# Part1: Retrieve all pages associated with
# the tag & sort them
# -----------------------------------------
# retrieve the tag string
tag = locvar(:fd_tag)
# recover the relative paths to all pages that have that
# tag, these are paths like /blog/page1
rpaths = globvar("fd_tag_pages")[tag]
# you might want to sort these pages by chronological order
# you could also only show the most recent 5 etc...
sorter(p) = begin
# retrieve the "date" field of the page if defined, otherwise
# use the date of creation of the file
pvd = pagevar(p, :date)
if isnothing(pvd)
return Date(Dates.unix2datetime(stat(p * ".md").ctime))
end
return pvd
end
sort!(rpaths, by=sorter, rev=true)
# --------------------------------
# Part2: Write the HTML to plug in
# --------------------------------
# instantiate a buffer in which we will write the HTML
# to plug in the tag page
c = IOBuffer()
write(c, "...1...")
# go over all paths
for rpath in rpaths
# recover the url corresponding to the rpath
url = get_url(rpath)
# recover the title of the page if there is one defined,
# if there isn't, fallback on the path to the page
title = pagevar(rpath, "title")
if isnothing(title)
title = "/$rpath/"
end
# write some appropriate HTML
write(c, "...2...")
end
# finish the HTML
write(c, "...3...")
# return the HTML string
return String(take!(c))
end
```
For instance the default uses:
```html
<!-- 1, 3: simple list-->
<ul>...</ul>
<!-- 2: simple list item plugging in path + title -->
<li><a href="/$rpath/">$title</a></li>
```