Skip to content

v2.0.1: cleanup injection code #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## quarto-svelte 2.0.1

- Improvement: extraneous OJS import code is removed from bootstrapping script

## quarto-svelte 2.0.0

- Rename Sverto to quarto-svelte
Expand Down
2 changes: 1 addition & 1 deletion _extensions/quarto-svelte/_extension.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title: quarto-svelte
author: James Goldie
version: 2.0.0
version: 2.0.1
quarto-version: ">=1.5.46"
contributes:
filters:
Expand Down
25 changes: 2 additions & 23 deletions _extensions/quarto-svelte/quarto-svelte.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,7 @@ function inject_svelte_and_compile(m)
-- either add text to start of body (and return nil), or return a rawblock
-- %s: compiled svelte js path
-- %s: obj_name
local svelte_js_import_template = [[
<script type="module">

// when the doc is ready, find quarto's ojs and inject svelte import
document.addEventListener("DOMContentLoaded", () => {

import("%s").then(svelteModule => {

const ojsModule = window._ojs?.ojsConnector?.mainModule
if (ojsModule === undefined) {
console.error("Quarto OJS module not found")
}

// TODO - check to see if there's already a variable with that name
const quartoSvelteImport = ojsModule?.variable()
quartoSvelteImport?.define("%s", svelteModule)

})

})
</script>
]]
local svelte_js_import_template = '<script src="%s" type="module"></script>'

-- abort if quarto-svelte.use is not a string or a list of MetaInlines
local quarto_svelte_use = util.get_svelte_paths_from_meta(m)
Expand All @@ -80,7 +59,7 @@ function inject_svelte_and_compile(m)

-- ... and inject the ojs init code for it
local svelte_insert = string.format(svelte_js_import_template,
web_path, obj_name)
web_path)
quarto.doc.include_text("before-body", svelte_insert)

-- finally, if we're rendering a single doc (not in a project),
Expand Down
4 changes: 4 additions & 0 deletions docs/news.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ title: News
date: last-modified
---

## quarto-svelte 2.0.1

- Improvement: extraneous OJS import code is removed from bootstrapping script

## quarto-svelte 2.0.0

- Rename Sverto to quarto-svelte
Expand Down