-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
23 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
<div id="content">Loading...</div> | ||
|
||
{{ $contentPath := .Get "contentPath" }} | ||
{{ $jsonKey := .Get "jsonKey" }} | ||
{{ $fullURL := printf "%s%s" .Site.BaseURL $contentPath }} | ||
|
||
<script> | ||
const url = '{{ .Get "url" }}'; // Get the URL from the shortcode parameter | ||
const url = '{{ $fullURL }}'; | ||
const jsonKey = '{{ $jsonKey }}'; | ||
|
||
fetch(url) // Fetch the markdown content | ||
fetch(url) // Fetch the JSON file | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Error fetching the markdown data'); | ||
throw new Error('Error fetching the JSON data'); | ||
} | ||
return response.text(); | ||
return response.json(); | ||
}) | ||
.then(markdown => { | ||
// Convert the markdown to HTML | ||
.then(data => { | ||
if (!data[jsonKey]) { | ||
throw new Error(`Key "${jsonKey}" not found in the JSON data`); | ||
} | ||
|
||
// Extract the value for the key and convert the markdown to HTML | ||
let markdown = data[jsonKey]; | ||
let htmlContent = marked.parse(markdown); | ||
|
||
// Inject the HTML into the content div | ||
document.getElementById('content').innerHTML = htmlContent; | ||
}) | ||
.catch(error => { | ||
document.getElementById('content').textContent = 'Error loading markdown content: ' + error.message; | ||
document.getElementById('content').textContent = 'Error loading content: ' + error.message; | ||
}); | ||
</script> |