-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.jl
190 lines (177 loc) · 4.42 KB
/
utils.jl
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
using Pkg, Markdown, JSON
function installed()
deps = Pkg.dependencies()
installs = Dict{String, Any}()
for (_, dep) in deps
dep.is_direct_dep || continue
installs[dep.name] = dep.version
end
return installs
end
const jso_pkgs = [
"ADNLPModels",
"AMD",
"AmplNLReader",
"BasicLU",
"BenchmarkProfiles",
"BundleAdjustmentModels",
"CaNNOLeS",
"CUTEst",
"DCISolver",
"HSL",
"JSOSolvers",
"Krylov",
"LDLFactorizations",
"LimitedLDLFactorizations",
"LinearOperators",
"LLSModels",
"ManualNLPModels",
"MUMPS",
"NLPModels",
"NLPModelsIpopt",
"NLPModelsJuMP",
"NLPModelsKnitro",
"NLPModelsModifiers",
"NLPModelsTest",
"NLSProblems",
"OptimizationProblems",
"PDENLPModels",
"Percival",
"PROPACK",
"QPSReader",
"QRMumps",
"QuadraticModels",
"RipQP",
"SolverBenchmark",
"SolverCore",
"SolverTest",
"SolverTools",
"SparseMatricesCOO",
"SuiteSparseMatrixCollection",
]
function badge(name, version)
color, lbl_color = if name in jso_pkgs
h = div(360 * findfirst(name .== jso_pkgs), length(jso_pkgs))
"hsl($h,100%25,30%25)", "hsl($h,30%25,30%25)"
elseif version == "STDLIB"
"666", "444"
else
"666", "999"
end
badge_img = "<img class=\"badge\" src=\"https://img.shields.io/badge/$name-$version-$color?style=flat-square&labelColor=$lbl_color\">"
if name in jso_pkgs
link = "https://juliasmoothoptimizers.github.io/$name.jl/stable/"
"<a href=\"$link\">$badge_img</a>"
else
badge_img
end
end
function hfun_list_versions()
lt_file = locvar("fd_rpath")[1:end-2] * "jl"
lines = readlines(lt_file)
pkgs = String[]
for line in lines
if match(r"^using", line) !== nothing
sline = split(line[7:end], ", ")
append!(pkgs, sline)
end
end
pkgs = unique(sort(pkgs))
dict = installed()
out = ""
for pkg in pkgs
if haskey(dict, pkg)
out *= badge(pkg, dict[pkg]) * "\n"
elseif pkg in readdir(Base.Sys.STDLIB)
out *= badge(pkg, "STDLIB") * "\n"
end
end
out
end
function aux_latest()
data = JSON.parsefile("_data/docs.json")
data = sort(data, by=x->x["date"], rev=true)
data[1]
end
hfun_latest_link() = "https://jso-docs.github.io/" * aux_latest()["repo"]
hfun_latest_short() = aux_latest()["short"]
hfun_latest_title() = aux_latest()["title"]
function hfun_rfig(params)
# Building locally or the main site shouldn't add the link
repo = split(get(ENV, "GITHUB_REPOSITORY", "nothing/jso-docs.github.io"), "/")[2]
if repo == "jso-docs.github.io"
repo = ""
end
file = "/" * joinpath(repo, "assets", params[1])
caption = join(params[2:end], " ")
"""
<figure>
<img class=\"image\" src=\"$file\">
<figcaption>$caption</figcaption>
</figure>
"""
end
@delay function hfun_list_news()
output = ""
for year in sort(readdir("news-and-blogposts"), rev=true)
for post in sort(readdir("news-and-blogposts/$year"), rev=true)
filename = "news-and-blogposts/$year/$post"
link = "/" * splitext(filename)[1] * "/"
title = pagevar(filename, :title)
date = basename(filename)[1:10]
excerpt = pagevar(filename, :rss_description)
output *= """
<div class="news-item">
<a href="$link">
<span class="is-size-7 has-text-grey-dark">
$date
</span>
<br>
<span class="is-size-4 has-text-primary">
$title
</span>
<br>
<span class="has-text-grey-dark">
$excerpt
</span>
</a>
</div>
"""
end
end
return output
end
@delay function hfun_list_news_short()
year = sort(readdir("news-and-blogposts"), rev=true)[1]
post = sort(readdir("news-and-blogposts/$year"), rev=true)[1]
filename = "news-and-blogposts/$year/$post"
link = "/" * splitext(filename)[1] * "/"
title = pagevar(filename, :title)
date = basename(filename)[1:10]
excerpt = pagevar(filename, :rss_description)
output = """
<div class="news-item">
<a href="$link">
<span class="is-size-7 has-text-grey-dark">
$date
</span>
<br>
<span class="is-size-4 has-text-primary">
$title
</span>
<br>
<p class="has-text-grey-dark is-size-6">
$excerpt
</p>
</a>
</div>
"""
return output
end
function hfun_process_tutorials_data()
data = readlines("_data/docs.json")
data[1] = "const data = " * data[1]
return """<script type="text/javascript">
$(join(data))
</script>"""
end