build locally, not with CI

This commit is contained in:
jverzani 2022-06-07 16:01:21 -04:00
parent e36e700740
commit 6d8ac9ff37
82 changed files with 5251 additions and 104 deletions

1
.gitignore vendored
View File

@ -2,7 +2,6 @@
docs/Mainfest.toml docs/Mainfest.toml
docs/build docs/build
docs/site docs/site
/html
test/benchmarks.json test/benchmarks.json
Manifest.toml Manifest.toml
TODO.md TODO.md

View File

@ -1,4 +1,4 @@
# Replacing the calculator with a computer # From calculator to computer
```julia; echo=false; ```julia; echo=false;
@ -6,7 +6,7 @@ using CalculusWithJulia
using CalculusWithJulia.WeaveSupport using CalculusWithJulia.WeaveSupport
const frontmatter = ( const frontmatter = (
title = "Replacing the calculator with a computer", title = "From calculator to computer",
description = "Calculus with Julia: Replacing the calculator with a computer", description = "Calculus with Julia: Replacing the calculator with a computer",
tags = ["CalculusWithJulia", "precalc", "replacing the calculator with a computer"], tags = ["CalculusWithJulia", "precalc", "replacing the calculator with a computer"],
); );
@ -14,6 +14,7 @@ const frontmatter = (
nothing nothing
``` ```
Let us consider a basic calculator with buttons to add, subtract, Let us consider a basic calculator with buttons to add, subtract,
multiply, divide, and take square roots. Using such a simple thing is multiply, divide, and take square roots. Using such a simple thing is
certainly familiar for any reader of these notes. Indeed, a certainly familiar for any reader of these notes. Indeed, a
@ -934,6 +935,21 @@ val = sind(52)
numericq(val) numericq(val)
``` ```
###### Question
What is the value of
```math
\frac{sin(pi/3) - 1/2}{pi/3 - pi/6}
```
```julia; hold=true; echo=false;
val = (sin(pi/3) - 1/2)/(pi/3 - pi/6)
numericq(val)
```
###### Question ###### Question

View File

@ -2,6 +2,7 @@
This section will use the following packages: This section will use the following packages:
```julia ```julia
using CalculusWithJulia using CalculusWithJulia
using Plots using Plots

View File

@ -1,10 +0,0 @@
using WeavePynb
using Mustache
mmd(fname) = mmd_to_html(fname, BRAND_HREF="../toc.html", BRAND_NAME="Calculus with Julia")

View File

@ -1,11 +0,0 @@
---
title: Test
author: Chris Rackauckas
---
This is a test of the builder system.
```{julia; echo=false; skip="notebook"}
using CalculusWithJulia
CalculusWithJulia.WeaveSupport._footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])
```

View File

@ -1 +1,6 @@
# CalculusWithJuliaNotes # CalculusWithJuliaNotes
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://jverzani.github.io/CalculusWithJuliaNotes.jl/dev/)
A collection of [notes]((https://jverzani.github.io/CalculusWithJuliaNotes.jl/dev/)) related to using `Julia` in the study of Calculus.

View File

@ -1,4 +1,4 @@
derivatives_implicit_differentiation = "bb10e33f783d2e9dbe47bd8734cce6e3878454e4d029ce464d8f6483d5de616f" differentiable_vector_calculus_plots_plotting = "1fbca9144d419b406206671a04c6e5b954e1993192d53c1dfa3e132d8100b769"
alternatives_plotly_plotting = "38de16a0a8f975a4a69a7dca7e747ce3dbb42c9291fc9591852fee9668e85c61" alternatives_plotly_plotting = "38de16a0a8f975a4a69a7dca7e747ce3dbb42c9291fc9591852fee9668e85c61"
integral_vector_calculus_stokes_theorem = "072c2d4cead381d760b8617f75a4f3a2f9c3c7080ca2fe0d1b09937b09ba678c" integral_vector_calculus_stokes_theorem = "072c2d4cead381d760b8617f75a4f3a2f9c3c7080ca2fe0d1b09937b09ba678c"
derivatives_derivatives = "b7070253b31556a826bc277daeee8a81c64aaa16ab2ad3a653205a5c5e71d4e6" derivatives_derivatives = "b7070253b31556a826bc277daeee8a81c64aaa16ab2ad3a653205a5c5e71d4e6"
@ -62,10 +62,10 @@ ODEs_solve = "967c509f4b998a5f7a2f993fbb649dd52c99ed2ed4120c6d7726e04fc088f1c1"
misc_toc = "547986a9a3d581cdc62419a80b8e8e2128ae4e227337d643f855c9636433e3f3" misc_toc = "547986a9a3d581cdc62419a80b8e8e2128ae4e227337d643f855c9636433e3f3"
misc_quick_notes = "26d355d223cd562804037e96412ac766d5dcd997c42263819cf2c89504524e24" misc_quick_notes = "26d355d223cd562804037e96412ac766d5dcd997c42263819cf2c89504524e24"
precalc_functions = "a6d4928a59cf9eb4a8e3f36469819289c21911e756d73c9fa294eb421c9c686b" precalc_functions = "a6d4928a59cf9eb4a8e3f36469819289c21911e756d73c9fa294eb421c9c686b"
precalc_plotting = "1b85c91fb0488407a91b79c2613716b2788e50ca62520888e15676a63a7a966d" precalc_plotting = "a4b3a1ceda5abbd9950ff0724295bd6a3f83b8838a0c2a5bcfcf38f5caccce5e"
integrals_substitution = "b96fe31960c9c8b0a46e3f8f6011abd9a8deb2fcbe8cc5402692415bcb8c04f6" integrals_substitution = "b96fe31960c9c8b0a46e3f8f6011abd9a8deb2fcbe8cc5402692415bcb8c04f6"
precalc_calculator = "a400b6003b6093fe7efade92bb1adff4fe014a7e020529825be1692f36ae2653" precalc_calculator = "7ec826ee6eef52c97ba6f0aa7a54ef5e59a08dc4c3896b750cd3f586895761eb"
precalc_exp_log_functions = "bd5d1b555dd2c975f327ebf17d076ff390d6b480d35c52b3f88cdff441e6f2f3" precalc_exp_log_functions = "bd5d1b555dd2c975f327ebf17d076ff390d6b480d35c52b3f88cdff441e6f2f3"
derivatives_optimization = "70c1435c1b0bfa3921a72f5f3b296f78e6f4e06c11c85f9c3468cee82e704042"
differentiable_vector_calculus_plots_plotting = "1fbca9144d419b406206671a04c6e5b954e1993192d53c1dfa3e132d8100b769"
differentiable_vector_calculus_vector_fields = "bd852d03a2a3397337649b23898252a7db0a298b6427d3e78262d4457e87a90b" differentiable_vector_calculus_vector_fields = "bd852d03a2a3397337649b23898252a7db0a298b6427d3e78262d4457e87a90b"
derivatives_implicit_differentiation = "bb10e33f783d2e9dbe47bd8734cce6e3878454e4d029ce464d8f6483d5de616f"
derivatives_optimization = "70c1435c1b0bfa3921a72f5f3b296f78e6f4e06c11c85f9c3468cee82e704042"

View File

@ -41,11 +41,12 @@ force = parse(Bool, d["force"])
if isnothing(folder) && isnothing(file) if isnothing(folder) && isnothing(file)
build_pages(nothing, nothing, :html, force) build_pages(nothing, nothing, :html, force)
build_toc() build_toc()
else else
build_pages(folder, file, :html, force) build_pages(folder, file, :html, force)
end end
build_deploy()

188
docs/toc.jl Normal file
View File

@ -0,0 +1,188 @@
## Header and footer code
## includes log and table of contents
# keep up to date with misc/toc.jmd
table_of_contents = [
:precalc :calculator;
:precalc :variables;
:precalc :numbers_types;
:precalc :logical_expressions;
:precalc :vectors;
:precalc :ranges;
:precalc :functions;
:precalc :plotting;
:precalc :transformations;
:precalc :inversefunctions;
:precalc :polynomial;
:precalc :polynomial_roots;
:precalc :polynomials_package;
:precalc :rational_functions;
:precalc :exp_log_functions;
:precalc :trig_functions;
:precalc :julia_overview;
:limits :limits;
:limits :limits_extensions;
:limits :continuity;
:limits :intermediate_value_theorem;
:derivatives :derivatives;
:derivatives :numeric_derivatives;
:derivatives :symbolic_derivatives;
:derivatives :mean_value_theorem;
:derivatives :optimization;
:derivatives :first_second_derivatives;
:derivatives :curve_sketching;
:derivatives :linearization;
:derivatives :newtons_method;
:derivatives :more_zeros;
:derivatives :lhospitals_rule;
:derivatives :implicit_differentiation;
:derivatives :related_rates;
:derivatives :taylor_series_polynomials;
:integrals :area;
:integrals :ftc;
:integrals :substitution;
:integrals :integration_by_parts;
:integrals :partial_fractions;
:integrals :improper_integrals;
:integrals :mean_value_theorem;
:integrals :area_between_curves;
:integrals :center_of_mass;
:integrals :volumes_slice;
:integrals :arc_length;
:integrals :surface_area;
:ODEs :odes;
:ODEs :euler;
:ODEs :solve;
:ODEs :differential_equations;
:differentiable_vector_calculus :polar_coordinates;
:differentiable_vector_calculus :vectors;
:differentiable_vector_calculus :vector_valued_functions;
:differentiable_vector_calculus :scalar_functions;
:differentiable_vector_calculus :scalar_functions_applications;
:differentiable_vector_calculus :vector_fields;
:differentiable_vector_calculus :plots_plotting;
:alternatives :makie_plotting;
:alternatives :plotly_plotting;
:integral_vector_calculus :double_triple_integrals;
:integral_vector_calculus :line_integrals;
:integral_vector_calculus :div_grad_curl;
:integral_vector_calculus :stokes_theorem;
:integral_vector_calculus :review;
:alternatives :symbolics;
:misc :getting_started_with_julia
:misc :bibliography;
:misc :quick_notes;
:misc :julia_interfaces;
:misc :calculus_with_julia;
:misc :unicode
]
struct Logo
width::Int
end
Logo() = Logo(120)
const logo_url = "https://raw.githubusercontent.com/jverzani/CalculusWithJuliaNotes.jl/master/CwJ/misc/logo.png"
function Base.show(io::IO, ::MIME"text/html", l::Logo)
show(io, "text/html", Markdown.HTML("""
<img src="$(logo_url)" alt="Calculus with Julia" width="$(l.width)" />
"""))
end
header_cmd = """
HTML(\"\"\"
<div class="admonition info">
<a href="https://CalculusWithJulia.github.io">
<img src="$(logo_url)" alt="Calculus with Julia" width="48" />
</a>
<span style="font-size:32px">Calculus With Julia</span>
</div>
\"\"\")
"""
"""
Footer(:file, :directory)
Footer object for HTML display
"""
struct Footer
f
d
end
# create footer from basename of file, folder name
function footer_cmd(bnm, folder)
f = Footer(Symbol(bnm), Symbol(folder))
out = sprint(io -> show(io, "text/html", f))
"HTML(\"\"\"$(out)\"\"\")"
end
# compute from URL
file_dir(f::Symbol,d::Symbol) = (f,d)
function file_dir(f, d)
f = Symbol(last(split(foot.f, "/"))[1:end-4])
d = Symbol(split(foot.d, "/")[end])
f,d
end
function previous_current_next(foot::Footer)
f₀, d₀ = file_dir(foot.f, foot.d)
toc_url = "../index.html"
suggest_url = "https://github.com/jverzani/CalculusWithJuliaNotes.jl/edit/master/CwJ/$(d₀)/$(f₀).jmd"
prev_url = "https://calculuswithjulia.github.io"
next_url = "https://calculuswithjulia.github.io"
prev,nxt = prev_next(d₀, f₀)
if prev != nothing
d,f = prev
prev_url = "../$(d)/$(f).html"
end
if nxt != nothing
d,f = nxt
next_url = "../$(d)/$(f).html"
end
(base_url="https://calculuswithjulia.github.io",
toc_url=toc_url,
prev_url=prev_url,
next_url = next_url,
suggest_edit_url = suggest_url
)
end
function Base.show(io::IO, ::MIME"text/html", x::Footer)
home, toc, prev, next, suggest = previous_current_next(x)
show(io, "text/html", Markdown.parse("""
> [ previous]($prev) [ next]($next) [ table of contents]($toc) [ suggest an edit]($suggest)
"""))
end
# return :d,:f for previous and next
function prev_next(d,f)
vals = [table_of_contents[i,:] for i 1:size(table_of_contents,1)]
val = [d,f]
i = findfirst(Ref(val,) .== vals)
i == nothing && error(val)
i == 1 && return (prev=nothing, next=vals[2])
i == length(vals) && return (prev=vals[end-1], next=nothing)
return (prev=vals[i-1], next=vals[i+1])
end

View File

@ -9,12 +9,22 @@ using Pkg
using SHA using SHA
using TOML using TOML
include("toc.jl")
const _map = map # asyncmap const _map = map # asyncmap
# Unfortunately, trying to build files during CI proves too time
# intensive, so we keep a copy of built html files in ./html
# build files in CwJ -> html_dir
# cp html_dir -> build_dir during build
const repo_directory = joinpath(@__DIR__,"..") const repo_directory = joinpath(@__DIR__,"..")
const cache_file = joinpath(@__DIR__, "build_cache.toml") const html_dir = joinpath(repo_directory, "html")
const build_dir = joinpath(@__DIR__, "build") const build_dir = joinpath(@__DIR__, "build")
# cache SHA for each .jmd file to monitor changes
const cache_file = joinpath(@__DIR__, "build_cache.toml")
sha(s::IO) = bytes2hex(sha256(s)) sha(s::IO) = bytes2hex(sha256(s))
sha(path::AbstractString) = open(path, "r") do io sha(path::AbstractString) = open(path, "r") do io
sha(io) sha(io)
@ -40,92 +50,60 @@ function write_sha(folder, file)
write_cache(D) write_cache(D)
end end
# build file check sha in cache
# get jmd file from (folder, file) pair
function jmd_file(folder, file) function jmd_file(folder, file)
occursin(r"\.jmd$", file) || (file *= ".jmd") occursin(r"\.jmd$", file) || (file *= ".jmd")
joinpath(repo_directory, "CwJ", folder, file) joinpath(repo_directory, "CwJ", folder, file)
end end
# where to write html file from (folder, file) pair
function out_file(folder, file; ext=".html") function out_file(folder, file; ext=".html")
file = replace(file, r"\.jmd$" => "") file = replace(file, r"\.jmd$" => "")
joinpath(build_dir, folder, file * ext) joinpath(html_dir, folder, file * ext)
end end
# should we build this file? keep cache # should we build this file? Consult cache
# too much function build_fileq(folder, file; force=true)
# function build_fileq(folder, file; force=true) occursin(r"index.html", file) && return false
# force && return force force && return force
# file = replace(file, r"\.jmd$"=>"") file = replace(file, r"\.jmd$"=>"")
# key = join((folder, file), "_") key = join((folder, file), "_")
# D = read_cache() D = read_cache()
# jmd_sha = sha(jmd_file(folder, file)) jmd_sha = sha(jmd_file(folder, file))
# cache_sha = get(D, key, nothing) cache_sha = get(D, key, nothing)
# Δ = jmd_sha != cache_sha Δ = jmd_sha != cache_sha
# return Δ return Δ
end
# # do we build the file check mtime
# function build_fileq(folder, file; force=false)
# force && return true
# jmdfile = jmd_file(folder, file)
# outfile = out_file(folder, file)
# !isfile(outfile) && return true
# mtime(outfile) < mtime(jmdfile) && return true
# return false
# end # end
# do we build the file check mtime
function build_fileq(folder, file; force=false)
force && return true
jmdfile = jmd_file(folder, file)
outfile = out_file(folder, file)
!isfile(outfile) && return true
mtime(outfile) < mtime(jmdfile) && return true
return false
end
## ---- ## ----
function build_toc(force=true) function build_toc(force=true)
@info "building table of contents" @info "building table of contents"
# copy misc/toc.html to index.html
jmd_dir = joinpath(repo_directory, "CwJ", "misc") a = joinpath(html_dir, "misc", "toc.html")
build_dir = joinpath(@__DIR__, "build") b = joinpath(build_dir, "index.html")
isdir(build_dir) || mkpath(build_dir) isdir(build_dir) || mkdir(build_dir)
cp(a, b; force=true)
file = joinpath(jmd_dir, "toc.jmd")
outfile = joinpath(build_dir, "index.html")
# cd(jmd_dir)
build_fileq(file, outfile, force=force) || return nothing
header = CalculusWithJulia.WeaveSupport.header_cmd
#footer = CalculusWithJulia.WeaveSupport.footer_cmd(bnm, folder)
html_content = md2html(file,
header_cmds=(header,),
footer_cmds=()
)
open(outfile, "w") do io
write(io, html_content)
end
# to use weave, not pluto
# weave(file;
# out_path=outfile,
# doctype="md2html",
# fig_ext=".svg",
# template=htmlfile,
# fig_path=tempdir())
end end
# do we build the file check mtime
# function build_file(jmdfile, outfile; force=false)
# force && return true
# !isfile(outfile) && return true
# mtime(outfile) < mtime(jmdfile) && return true
# return false
# end
# build pluto html # build pluto html
# file **has** ".jmd" extension # file **has** ".jmd" extension
@ -141,27 +119,26 @@ function build_file(folder, file, force)
bnm = replace(file, r"\.jmd$"=>"") bnm = replace(file, r"\.jmd$"=>"")
jmd_dir = joinpath(repo_directory, "CwJ", folder) jmd_dir = joinpath(repo_directory, "CwJ", folder)
#cd(jmd_dir) out_dir = joinpath(html_dir, folder)
isdir(out_dir) || mkpath(oud_dir)
dir = joinpath(build_dir, folder)
isdir(dir) || mkpath(dir)
html_content = try html_content = try
header = CalculusWithJulia.WeaveSupport.header_cmd header = header_cmd
footer = CalculusWithJulia.WeaveSupport.footer_cmd(bnm, folder) footer = footer_cmd(bnm, folder)
md2html(jmd_file(folder, file), md2html(jmd_file(folder, file),
header_cmds=(header,), header_cmds=(header,),
footer_cmds=(footer,) footer_cmds=(footer,)
) )
catch err catch err
@info "Error with $folder / $bnm" @info "Error with $folder / $bnm"
header = CalculusWithJulia.WeaveSupport.header_cmd header = header_cmd
md2html(jmd_file(folder, file), md2html(jmd_file(folder, file),
header_cmds=(header,) header_cmds=(header,)
) )
end end
outfile = joinpath(build_dir, folder, bnm * ".html") #outfile = joinpath(build_dir, folder, bnm * ".html")
outfile = joinpath(out_dir, bnm * ".html")
open(outfile, "w") do io open(outfile, "w") do io
write(io, html_content) write(io, html_content)
end end
@ -174,7 +151,7 @@ end
function build_all(force) function build_all(force)
folders = readdir(joinpath(repo_directory,"CwJ")) folders = readdir(joinpath(repo_directory,"CwJ"))
folders = filter(F -> isdir(joinpath(repo_directory, "CwJ", F)), folders) folders = filter(F -> isdir(joinpath(repo_directory, "CwJ", F)), folders)
asyncmap(F -> build_folder(F, force), folders) # _map _map(F -> build_folder(F, force), folders)
end end
function build_folder(folder, force) function build_folder(folder, force)
@ -197,8 +174,29 @@ function build_pages(folder=nothing, file=nothing, target=:html, force=false)
end end
end end
"""
Copy files from /html to /docs/build
recurse one level deep
"""
function build_deploy(;dir=html_dir)
isdir(build_dir) || mkdir(build_dir)
ds = readdir(dir)
for d ds
D = joinpath(build_dir, d)
isdir(D) || mkdir(D)
for dᵢ readdir(joinpath(dir,d))
a = joinpath(dir, d, dᵢ)
b = joinpath(D, dᵢ)
cp(a, b; force=true)
end
end
end
# ## -------------------------------------------------- # ## --------------------------------------------------
# ## Build more generally, but not use right now # ## Build more generally, but not used right now
# const cssfile = joinpath(@__DIR__, "..", "templates", "skeleton_css.css") # const cssfile = joinpath(@__DIR__, "..", "templates", "skeleton_css.css")
# const htmlfile = joinpath(@__DIR__, "..", "templates", "bootstrap.tpl") # const htmlfile = joinpath(@__DIR__, "..", "templates", "bootstrap.tpl")
# const latexfile = joinpath(@__DIR__, "..", "templates", "julia_tex.tpl") # const latexfile = joinpath(@__DIR__, "..", "templates", "julia_tex.tpl")

File diff suppressed because one or more lines are too long

69
html/ODEs/euler.html Normal file

File diff suppressed because one or more lines are too long

69
html/ODEs/odes.html Normal file

File diff suppressed because one or more lines are too long

69
html/ODEs/solve.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

69
html/integrals/area.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

69
html/integrals/ftc.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

69
html/limits/limits.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

69
html/misc/toc.html Normal file

File diff suppressed because one or more lines are too long

69
html/misc/unicode.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

69
html/precalc/ranges.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

69
html/precalc/vectors.html Normal file

File diff suppressed because one or more lines are too long