Skip to content

Commit 88a75c3

Browse files
authored
Merge pull request #25 from bhoov/main
Fixes #24, fixes #23, bumps Sverto to v1.0.1
2 parents bf1d4c7 + 6f00fed commit 88a75c3

File tree

4 files changed

+57
-27
lines changed

4 files changed

+57
-27
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@
2121
/docs/.sverto/
2222

2323
# sverto extension in docs site (we get it from project root on render)
24-
/docs/_extensions/sverto
24+
/docs/_extensions/sverto
25+
26+
# rendered single doc example files
27+
/example_files/

_extensions/sverto/_extension.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
title: Sverto
22
author: James Goldie
3-
version: 1.0.0
3+
version: 1.0.1
44
quarto-version: ">=1.4.0"
55
contributes:
66
filters:

_extensions/sverto/sverto-prerender.lua

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
-- fileExists: true if the file at `name` exists
2+
-- from https://pandoc.org/lua-filters.html#building-images-with-tikz
3+
local function fileExists(name)
4+
local f = io.open(name, 'r')
5+
if f ~= nil then
6+
io.close(f)
7+
return true
8+
else
9+
return false
10+
end
11+
end
12+
13+
-- getRollupConfig: return the path to the rollup config file
14+
local function getRollupConfig()
15+
if fileExists("./_extensions/jimjam-slam/sverto/rollup.config.js") then
16+
return "./_extensions/jimjam-slam/sverto/rollup.config.js"
17+
elseif fileExists("./_extensions/sverto/rollup.config.js") then
18+
return "./_extensions/sverto/rollup.config.js"
19+
else
20+
print("Error: no rollup config found. Is Sverto installed properly?")
21+
os.exit(1)
22+
end
23+
end
124

225
-- return contents of named file
326
function read_file(name)
@@ -30,18 +53,6 @@ end
3053
-- end
3154
-- end
3255

33-
-- file_exists: true if the file at `name` exists
34-
-- from https://pandoc.org/lua-filters.html#building-images-with-tikz
35-
function file_exists(name)
36-
local f = io.open(name, 'r')
37-
if f ~= nil then
38-
io.close(f)
39-
return true
40-
else
41-
return false
42-
end
43-
end
44-
4556
-- offset a relative `svelte_path` to a .qmd `input_path`, or an absolute
4657
-- `svelte_path` to the project path. then normalize.
4758
function offset_svelte_path(svelte_path, input_path)
@@ -119,20 +130,10 @@ for _, svelte_path in pairs(svelte_paths) do
119130
end
120131

121132
-- finally, call the svelte compiler via rollup
122-
rollup_config = ""
123-
if file_exists("./_extensions/jimjam-slam/sverto/rollup.config.js") then
124-
rollup_config = "./_extensions/jimjam-slam/sverto/rollup.config.js"
125-
elseif file_exists("./_extensions/sverto/rollup.config.js") then
126-
rollup_config = "./_extensions/sverto/rollup.config.js"
127-
else
128-
print("Error: no rollup config found. Is Sverto installed properly?")
129-
os.exit(1)
130-
end
131-
132133
cmd =
133134
get_cmd_prefix() ..
134135
"npm run build " ..
135-
rollup_config .. " -- " ..
136+
getRollupConfig() .. " -- " ..
136137
'--configQuartoOutPath="' .. os.getenv("QUARTO_PROJECT_OUTPUT_DIR") .. '" ' ..
137138
'--configSvelteInPaths="' .. svelte_path_string .. '"'
138139

_extensions/sverto/sverto.lua

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
-- fileExists: true if the file at `name` exists
2+
-- from https://pandoc.org/lua-filters.html#building-images-with-tikz
3+
local function fileExists(name)
4+
local f = io.open(name, 'r')
5+
if f ~= nil then
6+
io.close(f)
7+
return true
8+
else
9+
return false
10+
end
11+
end
12+
13+
-- getRollupConfig: return the path to the rollup config file
14+
local function getRollupConfig()
15+
if fileExists("./_extensions/jimjam-slam/sverto/rollup.config.js") then
16+
return "./_extensions/jimjam-slam/sverto/rollup.config.js"
17+
elseif fileExists("./_extensions/sverto/rollup.config.js") then
18+
return "./_extensions/sverto/rollup.config.js"
19+
else
20+
print("Error: no rollup config found. Is Sverto installed properly?")
21+
os.exit(1)
22+
end
23+
end
24+
125
-- append_to_file: append a string of `content` to the file with the path `name`
226
function append_to_file(name, content)
327
local file = io.open(name, "a")
@@ -96,12 +120,14 @@ function inject_svelte_and_compile(m)
96120
if quarto.project.directory ~= nil then
97121
quarto.log.info("Project found; deferring Svelte compilation to post-render script")
98122
else
123+
99124
local svelteCommand =
100-
"npm run build rollup.config.js -- " ..
125+
"npm run build " ..
126+
getRollupConfig() .. " -- " ..
101127
'--configQuartoOutPath="./" ' ..
102128
'--configSvelteInPaths="' .. sveltePaths .. '"'
103129
local svelteResult = os.execute(svelteCommand)
104-
quarto.log.warning("Svelte compiler finished with code " .. svelteResult)
130+
quarto.log.warning("Svelte compiler finished with code " .. tostring(svelteResult))
105131

106132
end
107133
end

0 commit comments

Comments
 (0)