Skip to content

Commit 118ba74

Browse files
committed
update extensions
1 parent 178e214 commit 118ba74

4 files changed

Lines changed: 201 additions & 7 deletions

File tree

docs/_extensions/machow/interlinks/_extension.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ version: 1.0.0
44
quarto-required: ">=1.2.0"
55
contributes:
66
filters:
7-
- interlinks.py
7+
- interlinks.lua
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
local function read_json(filename)
2+
local file = io.open(filename, "r")
3+
if file == nil then
4+
return nil
5+
end
6+
local str = file:read("a")
7+
file:close()
8+
return quarto.json.decode(str)
9+
end
10+
11+
local inventory = {}
12+
13+
function lookup(search_object)
14+
15+
local results = {}
16+
for ii, inventory in ipairs(inventory) do
17+
for jj, item in ipairs(inventory.items) do
18+
-- e.g. :external+<inv_name>:<domain>:<role>:`<name>`
19+
if item.inv_name and item.inv_name ~= search_object.inv_name then
20+
goto continue
21+
end
22+
23+
if item.name ~= search_object.name then
24+
goto continue
25+
end
26+
27+
if search_object.role and item.role ~= search_object.role then
28+
goto continue
29+
end
30+
31+
if search_object.domain and item.domain ~= search_object.domain then
32+
goto continue
33+
else
34+
table.insert(results, item)
35+
36+
goto continue
37+
end
38+
39+
::continue::
40+
end
41+
end
42+
43+
if #results == 1 then
44+
return results[1]
45+
end
46+
if #results > 1 then
47+
print("Found multiple matches for " .. search_object.name)
48+
quarto.utils.dump(results)
49+
return nil
50+
end
51+
if #results == 0 then
52+
print("Found no matches for object:")
53+
quarto.utils.dump(search_object)
54+
end
55+
56+
return nil
57+
end
58+
59+
function mysplit (inputstr, sep)
60+
if sep == nil then
61+
sep = "%s"
62+
end
63+
local t={}
64+
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
65+
table.insert(t, str)
66+
end
67+
return t
68+
end
69+
70+
local function normalize_role(role)
71+
if role == "func" then
72+
return "function"
73+
end
74+
return role
75+
end
76+
77+
local function build_search_object(str)
78+
local starts_with_colon = str:sub(1, 1) == ":"
79+
local search = {}
80+
if starts_with_colon then
81+
local t = mysplit(str, ":")
82+
if #t == 2 then
83+
-- e.g. :py:func:`my_func`
84+
search.role = normalize_role(t[1])
85+
search.name = t[2]:match("%%60(.*)%%60")
86+
elseif #t == 3 then
87+
-- e.g. :py:func:`my_func`
88+
search.domain = t[1]
89+
search.role = normalize_role(t[2])
90+
search.name = t[3]:match("%%60(.*)%%60")
91+
elseif #t == 4 then
92+
-- e.g. :ext+inv:py:func:`my_func`
93+
search.external = true
94+
95+
search.inv_name = t[1]:match("external%+(.*)")
96+
search.domain = t[2]
97+
search.role = normalize_role(t[3])
98+
search.name = t[4]:match("%%60(.*)%%60")
99+
else
100+
print("couldn't parse this link: " .. str)
101+
return {}
102+
end
103+
else
104+
search.name = str:match("%%60(.*)%%60")
105+
end
106+
107+
if search.name == nil then
108+
print("couldn't parse this link: " .. str)
109+
return {}
110+
end
111+
112+
if search.name:sub(1, 1) == "~" then
113+
search.shortened = true
114+
search.name = search.name:sub(2, -1)
115+
end
116+
return search
117+
end
118+
119+
function report_broken_link(link, search_object, replacement)
120+
-- TODO: how to unescape html elements like [?
121+
return pandoc.Code(pandoc.utils.stringify(link.content))
122+
end
123+
124+
function Link(link)
125+
-- do not process regular links ----
126+
if not link.target:match("%%60") then
127+
return link
128+
end
129+
130+
-- lookup item ----
131+
local search = build_search_object(link.target)
132+
local item = lookup(search)
133+
134+
-- determine replacement, used if no link text specified ----
135+
local original_text = pandoc.utils.stringify(link.content)
136+
local replacement = search.name
137+
if search.shortened then
138+
local t = mysplit(search.name, ".")
139+
replacement = t[#t]
140+
end
141+
142+
-- set link text ----
143+
if original_text == "" then
144+
link.content = replacement
145+
end
146+
147+
-- report broken links ----
148+
if item == nil then
149+
return report_broken_link(link, search)
150+
end
151+
link.target = item.uri:gsub("%$$", search.name)
152+
153+
154+
return link
155+
end
156+
157+
function fixup_json(json, prefix)
158+
for _, item in ipairs(json.items) do
159+
item.uri = prefix .. item.uri
160+
end
161+
table.insert(inventory, json)
162+
end
163+
164+
return {
165+
{
166+
Meta = function(meta)
167+
local json
168+
local prefix
169+
for k, v in pairs(meta.interlinks.sources) do
170+
json = read_json(quarto.project.offset .. "/_inv/" .. k .. "_objects.json")
171+
prefix = pandoc.utils.stringify(v.url)
172+
fixup_json(json, prefix)
173+
end
174+
json = read_json(quarto.project.offset .. "/objects.json")
175+
if json ~= nil then
176+
fixup_json(json, "/")
177+
end
178+
end
179+
},
180+
{
181+
Link = Link
182+
}
183+
}

docs/_quarto.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project:
44
output-dir: _site
55

66
website:
7-
title: "Vetiver (Python)"
7+
title: "vetiver for Python"
88
description: "Version, share, deploy, and monitor your Python models"
99
repo-url: https://github.com/rstudio/vetiver-python
1010
repo-actions: [edit, issue]
@@ -22,7 +22,7 @@ website:
2222
href: https://github.com/rstudio/vetiver-python
2323
aria-label: Vetiver python GitHub
2424
navbar:
25-
background: primary
25+
background: light
2626
pinned: true
2727
logo: "figures/logo.svg"
2828
logo-alt: "vetiver-home"
@@ -48,7 +48,7 @@ website:
4848

4949
quartodoc:
5050
style: pkgdown
51-
title: "Vetiver-{{< env VERSION >}}"
51+
title: "Vetiver:v{{< env VERSION >}}"
5252
package: vetiver
5353
renderer:
5454
style: markdown
@@ -66,7 +66,8 @@ quartodoc:
6666
- title: Deploy
6767
desc: ""
6868
contents:
69-
- VetiverAPI
69+
- name: VetiverAPI
70+
children: linked
7071
- VetiverAPI.run
7172
- VetiverAPI.vetiver_post
7273
- vetiver_endpoint
@@ -98,7 +99,7 @@ metadata-files:
9899

99100
filters:
100101
- interlinks
101-
102+
102103
interlinks:
103104
sources: {}
104105

@@ -107,4 +108,7 @@ profile:
107108

108109
format:
109110
html:
110-
theme: sandstone
111+
theme:
112+
- sandstone
113+
- style.css
114+

docs/style.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*-- scss:defaults --*/
2+
.nav-link {
3+
color: #7f3c18 !important;
4+
}
5+
.navbar-title{
6+
color:#7f3c18
7+
}

0 commit comments

Comments
 (0)