From 783767344df5cfe3f90a208f449c7cbe60d51355 Mon Sep 17 00:00:00 2001 From: Omar Kohl Date: Fri, 3 Jan 2025 13:43:12 +0100 Subject: [PATCH] feat: add plotly JS dependency to website 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/ --- .github/workflows/gh-pages.yml | 9 +++++++++ website/.gitignore | 3 +++ website/config.toml | 5 +++++ website/layouts/partials/scripts.html | 4 ++++ website/package-lock.json | 22 ++++++++++++++++++++++ website/package.json | 22 ++++++++++++++++++++++ 6 files changed, 65 insertions(+) create mode 100644 website/layouts/partials/scripts.html create mode 100644 website/package-lock.json create mode 100644 website/package.json diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index c24793fbc..15a80ae44 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -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 diff --git a/website/.gitignore b/website/.gitignore index 88b956feb..39de0d2a5 100644 --- a/website/.gitignore +++ b/website/.gitignore @@ -1,3 +1,6 @@ /public /resources .hugo_build.lock + +/npm-debug.log +/node_modules \ No newline at end of file diff --git a/website/config.toml b/website/config.toml index 5f1fba63d..aaa632647 100644 --- a/website/config.toml +++ b/website/config.toml @@ -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] diff --git a/website/layouts/partials/scripts.html b/website/layouts/partials/scripts.html new file mode 100644 index 000000000..3380b1fab --- /dev/null +++ b/website/layouts/partials/scripts.html @@ -0,0 +1,4 @@ +{{ if .Params.usePlotly }} +{{ $plotly := resources.Get "js/plotly/plotly.min.js" }} + +{{ end }} diff --git a/website/package-lock.json b/website/package-lock.json new file mode 100644 index 000000000..f048e4c33 --- /dev/null +++ b/website/package-lock.json @@ -0,0 +1,22 @@ +{ + "name": "website", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "website", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "plotly.js-dist-min": "^2.35.3" + } + }, + "node_modules/plotly.js-dist-min": { + "version": "2.35.3", + "resolved": "https://registry.npmjs.org/plotly.js-dist-min/-/plotly.js-dist-min-2.35.3.tgz", + "integrity": "sha512-sz2HLP8gkysLx/BanM2PtJTtZ1PLPwdHwMWNri2YxLBy3IOeuDsVQtlmWa4hoK3j/fi4naaD3uZJqH5ozM3zGg==", + "license": "MIT" + } + } +} diff --git a/website/package.json b/website/package.json new file mode 100644 index 000000000..4c289e784 --- /dev/null +++ b/website/package.json @@ -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" + } +}