|
| 1 | +:numbered: |
| 2 | + |
| 3 | += A book template |
| 4 | + |
| 5 | +This is a template for a book or website written with http://asciidoctor.org/[asciidoctor]. The resulting template website looks like this: http://simon-m-mudd.github.io/Book_template/. If you want to make your own website or book just clone this repository. |
| 6 | +You will meed to install https://www.ruby-lang.org/en/[ruby], https://rubygems.org/[rubygems] and http://bundler.io/[bundler] to get it working. |
| 7 | + |
| 8 | +Install the ruby package `bundler` using |
| 9 | + |
| 10 | +[source,console] |
| 11 | +---- |
| 12 | +$ gem install bundler |
| 13 | +---- |
| 14 | + |
| 15 | +== Turning these files into pdf or html |
| 16 | + |
| 17 | +NOTE: If you want to set up your own book and website, skip to the next section. These instructions are just for turning the template into pdf and html files. |
| 18 | + |
| 19 | +We will use http://bundler.io/[bundler], which manages http://asciidoctor.org/[asciidoctor] and a a bunch of other stuff, to turn these files into pdf and html. The template files do this work for you so all you need to do to egt started is install https://www.ruby-lang.org/en/[ruby], https://rubygems.org/[rubygems] and http://bundler.io/[bundler] and then clone this repository into the directory of your choice from Github. |
| 20 | + |
| 21 | +Once you have bundler installed, you can build the book with: |
| 22 | + |
| 23 | +[source,console] |
| 24 | +---- |
| 25 | +$ bundler install |
| 26 | +$ bundle exec rake book:build |
| 27 | +---- |
| 28 | + |
| 29 | +This will build *html* and *pdf* versions of the book. |
| 30 | + |
| 31 | +You can also build an html only version: |
| 32 | + |
| 33 | +[source,console] |
| 34 | +---- |
| 35 | +$ bundler install |
| 36 | +$ bundle exec rake book:build_html |
| 37 | +---- |
| 38 | + |
| 39 | +WARNING: The build process will make a folder called `images` in the root directory, |
| 40 | +which on some systems must be deleted before new builds. This is a particular problem on Windows systems, where sometimes windows will stupidly not let you delete the `thumbs.db` file it automatically generates. To get around this, right click on the images directory and unselect `read only`, then you should be able to delete the folder. In general, however, as long as you do not look in the images directory you will not have this problem. |
| 41 | + |
| 42 | +=== Quick build asciidoctor (i.e., not using bundler) |
| 43 | + |
| 44 | +You can also quickly generate the document by installing http://asciidoctor.org/[asciidoctor], and then running it on the `LSDTT_Book.asc` file: |
| 45 | + |
| 46 | +[source,console] |
| 47 | +---- |
| 48 | +$ gem install asciidoctor |
| 49 | +$ asciidoctor Book_template_top.asc |
| 50 | +---- |
| 51 | + |
| 52 | +WARNING: This quick generation will give you the text and cross-linking, but the images will not be linked. |
| 53 | +For images to be properly linked you need to run `bundle exec` (see above). |
| 54 | + |
| 55 | + |
| 56 | +== If you want to set up your own book, and have an associated website on github.io |
| 57 | + |
| 58 | +. The point of this template is to allow you to build a nice book that is easily converted to html. One nice place to host this website is https://github.com/[github]. These are instructions for starting your own book using the template, and setting it up as a github.io website. |
| 59 | +. The first thing you need to do is make a directory for your very own book. Lets call it `MyBook`. Go into `MyBook` and clone this template into a directory called master: |
| 60 | ++ |
| 61 | +[source,console] |
| 62 | +---- |
| 63 | +$ mkdir MyBook |
| 64 | +$ cd MyBook |
| 65 | +$ git clone https://github.com/simon-m-mudd/Book_template.git master |
| 66 | +---- |
| 67 | ++ |
| 68 | +. Next, **delete** the `.git` directory inside the `master` directory. |
| 69 | +. At this point you might want to rename some of the files and folders to suit your new book or website. If you forget to do this you can always change the names of files and directories by using the `git mv` command. |
| 70 | +. Now use `git init` to start a new repository and then add and commit the files. |
| 71 | ++ |
| 72 | +[source,console] |
| 73 | +---- |
| 74 | +$ cd master |
| 75 | +$ git init |
| 76 | +$ git add . |
| 77 | +$ git commit -m "Added the files" . |
| 78 | +---- |
| 79 | ++ |
| 80 | +. Now start a new repository on github **without a readme**. |
| 81 | +. It will give you the remote name. Add it to the repository: |
| 82 | ++ |
| 83 | +[source,console] |
| 84 | +---- |
| 85 | +$ git remote add origin https://github.com/MYUSERNAME/MYREPONAME.git |
| 86 | +$ git push origin master |
| 87 | +---- |
| 88 | ++ |
| 89 | +You will need to replace `MYUSERNAME` and `MYREPONAME` with the appropraite names. |
| 90 | ++ |
| 91 | +. Refresh the github repository page. You should see all the files from the template. |
| 92 | +. Now on the repository page, look above the files: you should see a tab for "Branches". |
| 93 | +Click on this and make a new branch called `gh-pages`. |
| 94 | ++ Now go back into your terminal window, go down a level using `cd ..`, and clone the **gh-pages** branch. |
| 95 | ++ |
| 96 | +[source, console] |
| 97 | +---- |
| 98 | +$ cd .. |
| 99 | +$ git clone https://github.com/MYUSERNAME/MYREPONAME.git gh-pages |
| 100 | +---- |
| 101 | ++ |
| 102 | +. Go into the gh-pages directory, check out the gh-pages branch, and delete the master branch (it will only delete the master branch form this directory). |
| 103 | ++ |
| 104 | +[source, console] |
| 105 | +---- |
| 106 | +$ cd gh-pages |
| 107 | +$ git checkout origin/gh-pages -b gh-pages |
| 108 | +$ git branch -d master |
| 109 | +---- |
| 110 | +. You gh-pages branch is still full of rubbish you don't need. Remove it all. Then make a dummy index page. |
| 111 | ++ |
| 112 | +[source, console] |
| 113 | +---- |
| 114 | +$ git rm -rf . |
| 115 | +$ echo "My Page" > index.html |
| 116 | +$ git add index.html |
| 117 | +$ git commit -m "Added the index" . |
| 118 | +$ git push origin gh-pages |
| 119 | +---- |
| 120 | ++ |
| 121 | +. Go back to the *master* folder and build the book: |
| 122 | ++ |
| 123 | +[source, console] |
| 124 | +---- |
| 125 | +$ cd .. |
| 126 | +$ cd master |
| 127 | +$ bundle exec rake book:build_html |
| 128 | +---- |
| 129 | ++ |
| 130 | +WARNING: If you are on Windows and using *git bash*, it will not recognise Ruby commands, so you will need to open a separate powershell window to run the *bundle* command. This should not be a problem on Linux and MacOS. |
| 131 | ++ |
| 132 | +. This will create a directory called *images* and an html file called *My_book.html*. |
| 133 | ++ |
| 134 | +. Rename *My_book.html* to *index.html* and copy it as well as the *images* directory into the *gh-pages* directory. |
| 135 | ++ |
| 136 | +. Now go back into the *gh-pages* directory, add the *images* directory, and then `commit` and `push` the changes (the below commands assume you are sitting in the `master` directory): |
| 137 | ++ |
| 138 | +[source, console] |
| 139 | +---- |
| 140 | +$ cd .. |
| 141 | +$ cd gh-pages |
| 142 | +$ git add images |
| 143 | +$ git commit -m "Updated the website" . |
| 144 | +$ git push origin gh-pages |
| 145 | +---- |
| 146 | ++ |
| 147 | +IMPORTANT: You **MUST** push to the **gh-pages** branch!! When you work in the **master** directory you `push` and `pull` to the **master** branch, and when you work in the **gh-pages** folder you `push` and `pull` from the **gh-pages** branch! If you mess this up you might have some painful cleaning up to do. |
| 148 | ++ |
| 149 | +. Okay, you should now be able to look at your website on: http://MYUSERNAME.github.io/MYREPONAME, where `MYUSERNAME` is your github username and `MYREPONAME` is the name of the repo in which you stored your new book. |
| 150 | + |
| 151 | + |
| 152 | +== If you are making changes to this template |
| 153 | + |
| 154 | +NOTE: You can ignore this unless you are helping write the template and have push permission. Currently this applies to nobody so they are more notes for myself to remember how I set up this repository. |
| 155 | + |
| 156 | +I do not want any messy merging conflicts! To avoid this please keep the *master* and *gh-pages* separate on your computer! |
| 157 | + |
| 158 | +. When checking out the code, check them out into two directories: |
| 159 | ++ |
| 160 | +[source, console] |
| 161 | +---- |
| 162 | +$ git clone https://github.com/simon-m-mudd/book_template.git master |
| 163 | +$ git clone https://github.com/simon-m-mudd/book_template.git gh-pages |
| 164 | +---- |
| 165 | ++ |
| 166 | +. In the gh-pages directory, check out the gh-pages branch and get rid of the master branch: |
| 167 | ++ |
| 168 | +[source, console] |
| 169 | +---- |
| 170 | +$ cd gh-pages |
| 171 | +$ git checkout origin/gh-pages -b gh-pages |
| 172 | +$ git branch -d master |
| 173 | +---- |
| 174 | ++ |
| 175 | +. Now, go back to the master branch, you can make changes there. |
| 176 | + |
| 177 | +. When you commit changes to the master branch and you want to update the website, commit and push changes, then run bundle: |
| 178 | ++ |
| 179 | +[source, console] |
| 180 | +---- |
| 181 | +$ pwd |
| 182 | +my/path/to/repo/book_template/master/ |
| 183 | +$ git commit -m "My latest commit" . |
| 184 | +$ git push -u origin master |
| 185 | +$ bundle exec rake book:build_html |
| 186 | +---- |
| 187 | ++ |
| 188 | +. Now copy any new image files to the /images folder in the gh-pages branch (you will need to git add them), |
| 189 | +and rename *My_book.html* to *index.html* and copy to the gh-pages folder. |
| 190 | ++ |
| 191 | +[source, console] |
| 192 | +---- |
| 193 | +$ pwd |
| 194 | +my/path/to/repo/book_template/gh-pages/ |
| 195 | +$ cd images |
| 196 | +$ git add <filenames of new images> |
| 197 | +$ cd .. |
| 198 | +$ git commit "updating website" . |
| 199 | +---- |
| 200 | ++ |
| 201 | +. Now push the changes to the gh-pages branch |
| 202 | ++ |
| 203 | +[source, console] |
| 204 | +---- |
| 205 | +$ bundle exec rake book:build_html |
| 206 | +---- |
| 207 | ++ |
| 208 | +[source, console] |
| 209 | +---- |
| 210 | +$ pwd |
| 211 | +my/path/to/repo/book_template/gh-pages/ |
| 212 | +$ git push -u origin gh-pages |
| 213 | +---- |
0 commit comments