Giter Site home page Giter Site logo

drmowinckels / bookdown_password Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 2.0 508 KB

example of how to set up password protection on rendered bookdown book

Home Page: https://athanasiamo.github.io/bookdown_password/

R 2.99% Shell 13.00% TeX 74.66% CSS 9.35%

bookdown_password's Introduction

This is a minimal example of a book based on R Markdown and bookdown (https://github.com/rstudio/bookdown). Please see the page "Get Started" at https://bookdown.org/ for how to compile this example.

Here the rendered book version is password protected through a js script in the docs-folder, together with the landing index.html.

The JS-script translates the password into a SHA215 has-key, this is the folder name within docs/ folder that the book should be rendered into. In the _bookdown.yml you need to add the extra option output_dir: "docs/GENERATED_SHA_HASH_FROM_PASSWORD". This means that when you build the book locally (with bookdown::render_book("index.Rmd", "bookdown::gitbook")), the book will be built into that specified folder, which will also be generated by the command.

I recommend having a small script handy to purge this dacs/hash/ directory, rebuild based on new docs, commit and puch to github in a script in the repo (I call mine _deploy.sh), and have the simple R-code above in a script called _build.R.

# clone the repository to the book-output directory
git pull

# Purge the old files to make sure new ones are built
git rm -rf docs/SHA_GENERATED/

Rscript _build.R

git add --all *
git commit -m "Update the book"
git push -q origin master

If github repo has github pages turned on for the docs folder. You will land on the index.html page, which is directly in the docs folder. Once the correct password it typed in the field, an html iframe will cover the entire view-screen with the rendered book.

Figuring out the password

If you are having problems setting the correct password, comment out line 24 in docs/pass.html, and uncomment line 26. Re-knit docs/index.Rmd, and type in your desired password. Next to the password field, the corresponding SHA512 key should appear. Copy this string and paste it into your _output.yml as output_dir: "docs/GENERATED_SHA_HASH_FROM_PASSWORD".

For the password to work, the folder "docs/GENERATED_SHA_HASH_FROM_PASSWORD" needs to exist. Run bookdown::render_book("index.Rmd", "bookdown::gitbook") in your R-console to render to book, which will create all necessary documents into the output_dir specified above.

Typing the password on the landing page should now redirect you to your book. Once this procedure works, make sure to comment out line 26, and uncomment line 24 in docs/pass.html.

You can copy this repo and build further on it to set up your password protected rendered book.

The result can be seen at https://athanasiamo.github.io/bookdown_password/

bookdown_password's People

Contributors

drmowinckels avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bookdown_password's Issues

PDF download not working

Great work! works well for creating lecture notes in my university. I'm unable to download PDF when using password. Any help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.