Skip to content

Commit

Permalink
feat: add plotly JS dependency to website
Browse files Browse the repository at this point in the history
In order for a page to use it it must contain "usePlotly: true" in the front
matter.

Idea found here: https://www.oscarberg.com/blog/hugo-npm/
  • Loading branch information
omarkohl committed Jan 3, 2025
1 parent 490f407 commit 7837673
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ jobs:
hugo-version: 'latest'
extended: true

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'latest'

- name: Install npm packages
run: npm install
working-directory: website

- name: Build
run: hugo --minify
working-directory: website
Expand Down
3 changes: 3 additions & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/public
/resources
.hugo_build.lock

/npm-debug.log
/node_modules
5 changes: 5 additions & 0 deletions website/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ mainSections = ["posts"]
[markup.goldmark.renderer]
unsafe = true # enable html in markdown

[module]
[[module.mounts]]
source = "./node_modules/plotly.js-dist-min"
target = "./assets/js/plotly"

[languages]

[languages.en]
Expand Down
4 changes: 4 additions & 0 deletions website/layouts/partials/scripts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ if .Params.usePlotly }}
{{ $plotly := resources.Get "js/plotly/plotly.min.js" }}
<script src="{{ $plotly.Permalink }}"></script>
{{ end }}
22 changes: 22 additions & 0 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "website",
"version": "1.0.0",
"description": "rationality-freiburg.de website - built with hugo (npm for JS dependency management)",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/omarkohl/rationality-freiburg.de.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/omarkohl/rationality-freiburg.de/issues"
},
"homepage": "https://github.com/omarkohl/rationality-freiburg.de#readme",
"dependencies": {
"plotly.js-dist-min": "^2.35.3"
}
}

0 comments on commit 7837673

Please sign in to comment.