DougBeney / jekyll-pug

Jekyll Plugin That Allows You To Use Pug
MIT License
37 stars 2 forks source link

Github Pages + Jekyll-pug #14

Closed ortonomy closed 6 years ago

ortonomy commented 6 years ago

Is it possible to use this plugin with github pages? (user.github.io)? I used it and then uploaded to my github site, but ostensibly doesn't seem to work. Any thoughts?

DougBeney commented 6 years ago

Unfortunately, no. Github picks and approves certain plugins. They have not added Jekyll-Pug.

ortonomy commented 6 years ago

😢

DougBeney commented 6 years ago

You could probably still get a usable setup with some scripting magic.

You would create a second repository. When you're ready to deploy, it would initialize git in your Jekyll build folder and then add your second repository as a remote. Finally, it would push changes to your second repository.

A little hacky, but once you get the system set up it should be pretty smooth.

I was going to create a Jekyll Plugin that would do exactly this, but then lost motivation to do so.

ortonomy commented 6 years ago

@DougBeney -- thanks for this. I had come to the same conclusion, and that's what I did!

I have my site on gh-pages branch and the actual site on master. I have the master branch cloned and tracked inside _site and then keep_files for .git folder and .gitignore in _config.yml.

Putting details here for anyone else who wants to do the same.

DougBeney commented 6 years ago

Very cool! Thanks for sharing.

lucasnantonio commented 6 years ago

@ortonomy could you please share a more in depth view on how to do this? 🙏

lucasnantonio commented 6 years ago

I got the same setup as you described above, but here's what I don't understand:

  1. I'll edit the site in gh-pages branch,
  2. then build it to _site folder which is tracking master branch.
  3. then commit and push both branches separately?
ortonomy commented 6 years ago

@lucasnantonio -- sure.

It's important to note that the same git repo is tracked twice, but on different branches, and nested in different folders.

  1. git clone [your repository]
  2. make sure you're on gh_pages branch, or create it.
  3. bundle exec jekyll build
  4. Push the whole repo as this page to remote
  5. cd [repo]/_site
  6. git clone [your repository] ./
  7. make sure you're on master branch.
  8. use finder or explorer or whatever (it's easier in a GUI) and remove all files except _site folder. That means the only folder you should have left is _site inside [repo]/_site/ (brain melt!)
  9. Copy all files from [repo]/_site/_site to [repo]/_site/
  10. Remove [repo]/_site/_site (it's not longer needed).
  11. Commit and push to master the contents of [repo]/_site/

This is the basis of having your site on master and gh-pages as the source branch

However, you need to make sure that the .git/ repo files and .gitignore files are not removed every time you run bundle exec jekyll build, so you need to edit your config.yml file and add these lines:

keep_files:
  - .git
  - .gitignore

Then you can run the build process any time you want, and it won't kill the repo.

Then commit master every time you want to push a new version of the page, or commit gh-pages branch to remotely store the source files.

My github.io repo is here if you want to see it as an example.

DougBeney commented 6 years ago

Thanks for sharing! I referenced this issue in the readme file.

mohsenkhanpour commented 5 years ago

You can also use git worktree: That will be one clone, multiple folders (one per branch). Also you can use a CI to build automatically to gh-pages branch whenever you commit to master.

zaz commented 5 years ago

Incase this is helpful to anyone, I set up a git repo in _site/ and then added a post-commit hook to the main repository (put below script in .git/hooks/post-commit). You will then be prompted after each commit on whether you want to add an equivalent commit to the _site repo.

Warning: Not thoroughly tested. Review code and use at your own risk.

# Exit on error (suffix ` || :` to prevent this)
set -e

echo -n "" >&2

run_summary()
{
    echo -n "$1... "
    shift
    # Print errors in red bold
    echo -n "\033[01;31m" >&2
    # Print "Success" or "Failure" in green or red bold
    "$@" >/dev/null \
        && echo "\033[01;32mSuccess\033[0m" \
        || (c="$?"; echo "\033[01;31mFailure\033[0m"; exit "$c")
    echo -n "\033[0m" >&2
}

echo -n "\033[01;1mDelete _site/, compile, and commit? (y/N) \033[0m"
read answer < /dev/tty
if [ "$answer" != "y" ]; then exit; fi

base=$( pwd )
message=$( git log -1 --pretty=%B )

mv _site/.git _site-git~37uh6 2>/dev/null || :
run_summary "Removing _site" rm -rf _site
mkdir -p _site
mv _site-git~37uh6 _site/.git 2>/dev/null || :

git stash --all
trap 'cd $base && git stash pop -q 2>&1 | grep -v "already exists, no checkout"' INT TERM EXIT

run_summary "Building" jekyll build

cd _site
    git init >/dev/null
    git add --all
    run_summary "Committing" git commit -m "$message"
cd ..

# XXX: already handled by trap EXIT
# git stash pop -q >/dev/null 2>/dev/null