Grav (Flat-File CMS) + Google Drive
Simplest blog publishing workflow is to just save a file and a image somewhere near.
I was considering a Dropbox daemon as service dropbox.service, but I figured out I have purchased Insync, and I also like a search integration of Google Drive on Android platform.
So, first, we need to install Google Drive on headless Linux box, and the only solution is Insync.
Insync as service
There is a headless version available.
As non-root:
wget -qO - https://d2t3ff60b2tol4.cloudfront.net/services@insynchq.com.gpg.key | sudo apt-key add -
echo "deb http://apt.insynchq.com/ubuntu vivid non-free contrib" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install insync-headless
Now, add our account:
# Everything is explained here
#
insync-headless help add_account
mkdir -p ~/gdrive/cvladan
insync-headless add_account -a '<AUTH_CODE>' -p ~/gdrive/cvladan
To check account status:
insync-headless get_account_information
To remove account, delete whole ~/.config/Insync
subdir and restart
account setup. Or type insync-headless remove_account cvladan@gmail.com
.
It wouldn’t sync, and the reason was:
insync-headless get_actions_required
That gave me Plus Trial has expired
.
To start it on boot, do: insync-headless set_autostart yes
. This will
add an entry to the crontab.
insync-headless pause_syncing
insync-headless manage_selective_sync cvladan@gmail.com
There is also command completion for InSync here.
More information found in these articles:
Automatic MySQL backups to Google Drive from Ubuntu — BRIGHTBULB Download Insync for Windows, Mac, and Linux Insync, Google Drive in Linux, Headless | { sneaky.Koder(); } Download Insync for Windows, Mac, and Linux How to control Insync via command line (CLI) - How-To - Insync Support ❤ Insync, Google Drive in Linux, Headless | { sneaky.Koder(); }
Dropbox as service
I considered the possibility to just symlink a folder from Google Drive to Dropbox and use Dropbox on Linux all the way. The problem lies in Windows OS as Dropbox can’t detect a changes in symlinked directories as explained here:
Windows doesn’t propagate file system events to both ends of the symlink, just the “real” end, so Dropbox never gets to hear about changes.
We can use the tool like Boxifier to do that in Windows, but that simply seemed too much of a hassle.
I wanted with Dropbox, just autostart for future: Dropbox setup on a headless Ubuntu Server (http://wp.me/pnbL6-5F) · GitHub Install Dropbox on your Linux box
~/.config/systemd/user/dropbox.service · GitHub Dropbox on Ubuntu server | bankras.org projects Install Dropbox on Ubuntu Server | jermsmit.com - Jermal Smith ubuntu 15.04 dropbox systemd · GitHub Ryan’s Blog: Headless Dropbox
Install Grav
First, check PHP is working:
echo "<?php phpinfo(); ?>" >_nfo.php
Basic Tutorial | Grav Documentation
Starting a Flat File Blog with Grav CMS Build a Flat-File Website with Grav CMS
cd /var/www/cvladan.com/web
# install grav
git clone https://github.com/getgrav/grav.git
cd grav
bin/grav install
# move grav to web root
cd ..
mv grav/* .
rm -r grav
chown -R --reference . *
# remove old default html page
rm index.html
It should work now.
Everything was beautiful. I just couldn’t make it work without a “folder per post” structure.
Real problems
- Folder per page
- No spaces in file names
The first one I accepted, but the second one is unacceptable.
So I fixed it:
Changes in Grav code: one will allow spaces in filenames and other create better slugs.
1. File: Pages.php
Function: protected function recurse
Code: if (preg_match('/^.*\/[0-9A-Za-z \-\_]+('.$extension.')$/', $found)) {
About: one space in regex
2. File: Page.php
Function: public function slug
Code: $this->slug = strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($this->folder, ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), '-'));
YAML Syntax | Grav Documentation Dashboard | Grav Documentation
cd /var/www/cvladan.com/web/user/pages
ln -s /home/upravitelj/gdrive/cvladan/Treasury/Public/Developer blog