How to add footer to pre-rendered html pages?

I have some pre-rendered HTML pages generated from Jupyter Notebook on my Jekyll site. Is it possible to write some Ruby (or other configuration) script to append a footer to these pages when they’re copied over to _site?

Specifically, I’d like to try and integrate Google Analytics automatically (which I have working for the .md files but not for the .html files).

Thanks,

Jon

Hi Jon

This is an unusual problem to solve as this is not typical jekyll approach and I haven’t seen a solution that works well for this. But I can see why you need it so I’ll add a suggestion

Yes you can write a ruby plugin in your repo that runs at build time to copy notebooks, appends to them (be careful to ensure the footer is still inside body tag) and writes to _site dir.
You’ll have to be careful that your plugin doesn’t run too early so it gets overridden by default behavior.
You can also have a plugin that runs directly as a script before jekyll build command

Here is material on how to do plugins that generate files

Note you’ll not be able to do it on plain Github Pages with a custom plugin. You’ll need Netlify.com or Github Actions (see Deployments CI CD section of docs)

Gotcha. I do have the site hosted on GitHub pages, so thank you for linking to those additional sources. I’ll have to decide whether it’s worth the effort. I don’t know Ruby (ugh) and I still feel like a huge Jekyll n00b.

Incidentally, the website is here: https://makeabilitylab.github.io/physcomp/, which we created to move our teaching resources online in response to Covid-19.

Thanks for the help Michael!

Jon

Hi Jon,

I’ve had a look at your github repo and its clear.

Your .MD files have “frontmatter” which is a data-structure that jekyll recognizes and adds the footer and google analytics.

Your HTML files do not have frontmatter and so jekyll directly copies them without making any additional changes.

Here is the first google result of a python script attempting to extract your notebook as Markdown and wraps into a jekyll template. http://www.leeclemmer.com/2017/07/04/how-to-publish-jupyter-notebooks-to-your-jekyll-static-website.html

1 Like

Oh yes I forgot to mention that. If you use Github Actions or Netlify you can create and run bash, node, python etc

./format_notebook.sh && jekyll build

Such as with Bash for one file without a for loop

echo "---
title: Foo
layout: nb-with-footer
---
" >> file.html
cat mynotebook.ipnb >> file.html
1 Like

Thanks all. I appreciate the help and the suggested solutions. Still not sure whether it’s worth my effort to pursue a programmatic approach vs. just manually editing the exported Notebook files.