How to use hexo server --draft and Livereload - livereload

I am writing draft blog posts using hexo. I am running the hexo server as follows:
hexo server --draft
This watches for changes in the draft folder and generates the draft posts which can be viewed at http://0.0.0.0:4000
The problem is I can't work out how to use live-reload while writing drafts.
With livereload I call
live-reload --port 9091 public/
And use use the javascript implementation with the browser
<script type="text/javascript" src="//localhost:9091"></script>
I can see why this doesn't work, live-reload is looking for changes to the public folder. With the server running in draft mode, I don't know what folder the html generated drafts are being stored in. I've searched my project structure and can't seem to see anything obvious. Any ideas?

Hexo can offer live-reload-like functionality via the'Browsersync-based' plugin, 'hexo-browsersync'.
There is actually also a hexo-livereload plugin, but the net, and hexo-browsersync's NPMJS rating, seem to favour the Browsersync Hexo plugin.
Christopher Martin's blog post 'Getting Started with the Hexo Blogging Framework', outlines the plugin's installation and usage, as well as many other helpful tips:
To install the hexo-browsersync plugin:
$ npm install hexo-browsersync --save
$ hexo server --draft --open #restart the server
This might possibly suit the OP's original question better than the accepted answer.

This is how I normally do this sort of thing:
hexo generate --draft --watch & live-server --port=4000 public
This generates the site in the public folder and watches for changes, whilst also serving said public folder with auto-updates.
Not exactly answering the specific question but maybe someone will find it useful.
Note: You will need to have live-server and hexo-cli installed globally, or locally if running via npm scripts.

hexo server serves the source version of the post not the public version. If you set livereload to watch the source folder livereload will work. I suggest setting livereload to use a 1 second or so delay before processing so the on the fly source generation to occur before reload is attempted.

Looking to the --draft option implementation at Github shows that it only extends the post processor to the _draft folder. So the place where it puts draft rendered files is the same it puts published posts.
However, hexo server does not save published posts in public directory as might be suggested by the question; public directory is populated by hexo generate command only. In fact hexo server does not save temporary files as it renders them on the fly.
I think live-reload will not work this way.

Related

jekyll on github pages ignores custom layout

I'm trying to clone the repo https://github.com/TowerofHanoi/towerofhanoi.github.io on my GitHub, based on the website https://toh.necst.it and publish it on a new GitHub pages instance. I'm doing this to check that a new article is well formatted for publication.
I'm having trouble generating the website on GitHub pages, the site is somehow bad: https://mencucci.github.io/towerofhanoi.github.io/ (my repo: https://github.com/Mencucci/towerofhanoi.github.io).
Locally on my Ubuntu machine, I can get the site to render properly with the following commands:
bundle init
bundle add jekyll
rm -rf \_site && bundle exec jekyll serve --verbose
I couldn't get the remote to build properly.
I tried:
adding a valid theme (no changes)
using a custom build action (no changes)
I noticed a difference in the logs: local, and github. The local log references the /_layout directory, but the remote one does not. Maybe it doesn't "see" the theme?
Thank you for your time
Figured it out, my main issue was that I was running the site using the default url, which hosts the site at <username>.github.io/<repo_name>. Some hard coded elements assumed that the site be hosted at domain root instead. I solved my issue by using a custom domain, which mapped the to the base domain (empty path).

Jekyll custom hook in `_plugins` folder is not executed

Before we start, I do know custom hooks are not executed by Github pages, I'm suffering this issue locally(bundle exec jekyll serve).
I manage my own Github pages, and I found a great post about Jekyll hook that I wanted to try it out by myself.
I followed the instruction, first created _plugins folder at the root of my repo,
and created my own *.rb file.
But my hook is not executed at all!
I even downloaded the source file of the example blog, but I couldn't notice any difference that might cause this issue.
FYI, local serve of the example blog worked well with all the hooks executed.
If you can help me on this issue, it would be very much appreciated. Here is the WiP commit of my blog.
Thank you.

Subdirectories in openshift project cannot be found

I built a site using a php openshift project and accessing the root directory via http works fine. However, all the root directories give me a 404 not found, like this one: http://test.toppagedesign.com/sites/
I checked with ssh, and /app-root/repo/sites and app-deployments/current/repo/sites/ both exist.
EDIT
Added a directory called php and now I have 503 errors for everything...
EDIT 2
I deleted the php directory, now the 503 errors are gone. However, I do still get 404 errors for the subdirectory.
Here is my directory tree: http://pastebin.com/hzPCsCua
And I do use git to deploy my project.
php is one of the alternate document roots that you can use, please see the March Release blog post here about this (https://www.openshift.com/blogs/openshift-online-march-2014-release-blog)
As for the sub-directories not working, can you ssh into your server and use the "tree" command to post the directory/file structure of your project? Also are you using Git to deploy your project or editing files directly on the server?
You need to have an index.php or index.html file in any directory that you want to work like app-domain.rhcloud.com/sites , if you just have sub-directories, how would it know what to show? Also, indexing (showing a folders contents) is not enabled for security reasons, and I believe there is no way to enable it.
This sounds like it could be a problem with how you are serving your static content.
I recently created a new sample app for OpenShift that includes:
a basic static folder
an .htaccess file (for serving assets in production)
support for using php's local server to handle the static content (in your dev environments)
Composer and Silex - a great starting point for most new PHP apps
You can serve the project locally if you have PHP-5.4 (or better), available in your dev environment:
php -S localhost:8080 -t static app.php
For a more advanced project that is built on the same foundation, take a look at this PHP+MongoDB mapping example. I wrote up a blog post with some notes on my process for composing that app as well.
Hope these examples help!

Site Not Generating New Files

My jekyll site is generating files fine on my computer but is not working at all on the server; I can edit the _site folder to make the changes happen, but it won't generate on the server. I am running jekyll --server with no errors. Any suggestions?
My _config.yml file is:
server: false
permalink: /:year/:title/
Are you running any plugins? Unless you have a server that can run Ruby, plugins won't run anywhere besides locally. GitHub doesn't allow Ruby to be run for security reasons.
I'm surprised it's generating fine locally, since you should probably have server:true. More info on your server setup would be helpful if this doesn't solve your issues.

Considering moving from WordPress to Jekyll: What goes where?

I'm trying to figure out what would be required to move my current blog from WordPress to Jekyll, as MySQL is really too complex for my taste at this point. I've read the docs on GitHub about Configuration, Usage etc, but Installation is less clear.
I assume that since posts, layouts and other files are kept locally, that the required Ruby gems are as well? At the same time, I've seen others talk about installing to a web host (Dreamhost in my case), which would be ideal, but I'm still not sure.
Also, I'm using Mercurial instead of Git for SCM, so I would probably need to make sure I can use something like Hg-Git to help deploy things. Any help would be greatly appreciated!
I think your question can be answered from two standpoints: 1) How to get Jekyll up and running and 2) How to get your current Wordpress content into jekyll. Here's answers to get you started with each in turn.
Part 1 - Getting Jekyll Up and Running
The first thing to realize is that Jekyll is designed to generate a set of static HTML files that can be served from basically any web server without the need for PHP, Ruby, Perl or any other dynamic server side processing.
Of course, Jekyll uses Ruby, so you have to have that running wherever you do the file generation. While that could be on the same server that serves the file the important point is that it doesn't have to be. For example, all of these are valid workflows for posting with Jekyll:
Create raw files on your personal machine, run Jekyll there to generate the static HTML files and then transfer them to your remote web server for the world to see.
Run Jekyll directly on your server doing all editing and creation of raw files there to have Jekyll process them for serving by the web server software on that machine.
Run Jekyll on your server machine, but edit the raw files on your local machine and push them to the server when you are ready to post. The Jekyll engine will take the raw files and do the static HTML file generation on the server itself.
People also have much more complex setups that allow them to post from either their laptops, their phones and the server itself and get everything synced up across the board via Dropbox. You can get as creative as you want with that, but I think the simplest one to get started with is the first one. Edit your raw files locally, run Jekyll locally and then transfer the resulting HTML files to your web server when you're ready for them to go live.
Installing Jekyll Locally
Obviously, you'll need Jekyll installed on your local machine for this. Directions for that can be found on the Github page. For myself, running Mac OS X 10.6, the following commands got me setup.
sudo gem install rubygems-update
sudo update_rubygems
sudo gem update
sudo gem update --system
sudo gem install rails
sudo gem install maruku
sudo gem install jekyll
Note: I don't think you actually need rails, but those are the steps I went through and they worked for me
Setting Up To Use Jekyll
Once you have Jekyll on your machine, getting a basic site setup is relatively simple. Create the following structure in an empty directory:
Directories:
_layouts
_posts
_site
Files and their content:
_config.yml
safe: false
auto: false
server: false
server_port: 4000
base-url: /
source: .
destination: ./_site
plugins: ./_plugins
future: true
lsi: false
pygments: false
markdown: maruku
permalink: date
maruku:
use_tex: false
use_divs: false
png_engine: blahtex
png_dir: images/latex
png_url: /images/latex
rdiscount:
extensions: []
kramdown:
auto_ids: true,
footnote_nr: 1
entity_output: as_char
toc_levels: 1..6
use_coderay: false
coderay:
coderay_wrap: div
coderay_line_numbers: inline
coderay_line_numbers_start: 1
coderay_tab_width: 4
coderay_bold_every: 10
coderay_css: style
This is the default configuration setup for Jekyll. You can get away without this file, but it throws a warning when the process runs that it can't find the file. So, I'd go ahead and set it up. It also makes it much easier to mess around with stuff instead of sending arguments to jekyll on the command line.
_layouts/default.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Jekyll Site</title>
</head>
<body>
<!-- This will be replaced with your content -->
{{ content }}
{{ site.posts }}
</body>
</html>
The {{ content }} string will be replaced by the processed content of the "index.md" file listed below. The {{ site.posts }} string will be replaced by a reverse chronological listing of the files in the "_posts" directory. GitHub has a full list of the template code snippets.
_posts/2011-07-29-my-first-jekyll-post.md
---
layout: default
---
# My first Jekyll post.
This is the content from 2011-07-29-my-first-jekyll-post.md
index.md
---
layout: default
---
# My Jekyll site
This is the content from index.md
It's worth pointing out here that you could use .html or .textile files instead of .md versions. As long as the had the YAML Front Matter, which is the first three lines consisting of the dashes and "layout: default", they will be processed by Jekyll.
Generating Static Files With Jekyll
Now that your starting file and directory structure is setup, simply bring up your command prompt, go to the directory where you create the index.md file and run the command jekyll. Assuming everything went well, you should see a short log of the process and you'll have two HTML files now sitting under:
_site/index.html
and
_site/2011/07/29/my-first-jekyll-post.html
It's worth pointing out Markdown (.md) files for the raw file source. You can also use .textile or .html as well.
Transferring/Deploying Files.
The last step with this approach is simply to use FTP or rsync to push the files up to the root of your web server and share them with the world. Since they are flat HTML, it should be quick and painless getting pretty much any hosting provide ready to go for them.
(In your question you mention Git and Mercurial. You can use either to do version control and/or deploy your raw files as well as the static HTML files the Jekyll generates, but neither is required for Jekyll to run or to transfer your files. It's all about how you want to setup the deployment process.)
Part 2 - Migrating Data From WordPress
Everything above has been about using Jekyll itself starting effectively from scratch. If you have been using WordPress (or any other engine for that matter) and want to keep the pages and posts you generated there, you'll need to migrate them from WordPress to Jekyll.
The basic idea is that you would move your posts and pages into corresponding locations inside the Jekyll directory and let it take over from there. I would start your research on that topic on the Jekyll Blog Migrations page.
(On a personal note, my first attempt at a WordPress migration didn't work out of the box. I haven't had a chance to jump back into it to get it going, but I'm committed to making it work. Moving to a much simpler static site that reduces the potential security issues, loads faster and is easier to maintain is totally worth having to deal with a migration for me.)
After you installed jekyll, you can try this wordpress plugin https://github.com/benbalter/wordpress-to-jekyll-exporter
As I understand it, Jekyll produces static HTML sites. Of course Jekyll consists of some Ruby software, but that's something you can run on any computer (e.g. your home computer rather than the web server). This way, your web hosting needs can be satisfied by simple static systems such as Github Pages. Now, Github can handle the Jekyll invocation for you automatically, but in general the idea is to upload static HTML to dumb web servers.
I don't think there's any need to use Git specifically with Jekyll-created sites—I'm sure even FTP would be fine.