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)