Some comments in the code

This commit is contained in:
Phyks 2013-10-22 22:39:11 +02:00
parent 7b44e77b3a
commit 548ad16f7b
2 changed files with 77 additions and 24 deletions

View File

@ -1,28 +1,51 @@
Blogit
======
A git based blogging software. Just as Jekyll and so, it takes your articles as html files and computes them to generate static page and RSS feed to serve behind a webserver. It uses git as a backend file manager (as git provide some useful features like history and hooks) and Python for scripting the conversion process. You can customize the python scripts to handle special tags (ie, not standard HTML tags) just as <code> for example. See params file in raw dir to modify this.
A git based blogging software. Just as Jekyll and so, it takes your articles as
html files and computes them to generate static page and RSS feed to serve
behind a webserver. It uses git as a backend file manager (as git provide some
useful features like history and hooks) and Python for scripting the conversion
process. You can customize the python scripts to handle special tags (ie, not
standard HTML tags) just as <code> for example. See params file in raw
dir to modify this.
This project is still a WIP.
How it works ?
==============
There are three directories under the tree : raw for your raw HTML articles and header/footer, gen (created by the script) for the temporary generated files and blog for the blog folder to serve behind the webserver.
There are three directories under the tree : raw for your raw HTML articles and
header/footer, gen (created by the script) for the temporary generated files
and blog for the blog folder to serve behind the webserver.
Articles must be in folders year/month/ARTICLE.html (ARTICLE is whatever you want) and some extras comments must be put in the article file for the script to handle it correctly. See the test.html example file for more info on how to do it.
Articles must be in folders year/month/ARTICLE.html (ARTICLE is whatever you
want) and some extras comments must be put in the article file for the script
to handle it correctly. See the test.html example file for more info on how to
do it.
You can put a file in "wait mode" and don't publish it yet, just by adding .ignore at the end of its filename; Every file that you put in raw and that is not a .html file is just copied at the same place in the blog dir (to put images in your articles, for example, just put them beside your articles and make a relative link in your HTML article).
You can put a file in "wait mode" and don't publish it yet, just by adding
.ignore at the end of its filename; Every file that you put in raw and that is
not a .html file is just copied at the same place in the blog dir (to put
images in your articles, for example, just put them beside your articles and
make a relative link in your HTML article).
You should change the params file (raw/params) before starting to correctly set your blog url, your email address and the blog title (among other parameters).
You should change the params file (raw/params) before starting to correctly set
your blog url, your email address and the blog title (among other parameters).
When you finish editing an article, just git add it and commit. The pre-commit.py hook will run automatically and generate your working copy.
When you finish editing an article, just git add it and commit. The
pre-commit.py hook will run automatically and generate your working copy.
Note about tags : Tags are automatically handled and a page for each tag is automatically generated. A page with all the articles for each month and each year is also automatically generated.
Note about tags : Tags are automatically handled and a page for each tag is
automatically generated. A page with all the articles for each month and each
year is also automatically generated.
Note : Don't remove gen/ content unless you know what you're doing. These files are temporary files for the blog generation but they are useful to regenerate the RSS feed for example. If you delete them, you may need to regenerate them.
Note : Don't remove gen/ content unless you know what you're doing. These files
are temporary files for the blog generation but they are useful to regenerate
the RSS feed for example. If you delete them, you may need to regenerate them.
Important note : This is currently a beta version and the hook isn't set to run automatically for now. You have to manually run pre-commit.py (or move it to .git/hooks but this has never been tested ^^).
Important note : This is currently a beta version and the hook isn't set to run
automatically for now. You have to manually run pre-commit.py (or move it to
.git/hooks but this has never been tested ^^).
Example of syntax for an article
================================
@ -38,16 +61,16 @@ Example of syntax for an article
LICENSE
=======
TLDR; I don't give a damn to anything you can do using this code. It would just be nice to
quote where the original code comes from.
TLDR; I don't give a damn to anything you can do using this code. It would just
be nice to quote where the original code comes from.
* --------------------------------------------------------------------------------
* -----------------------------------------------------------------------------
* "THE NO-ALCOHOL BEER-WARE LICENSE" (Revision 42):
* Phyks (webmaster@phyks.me) wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff (and you can also do whatever you want
* with this stuff without retaining it, but that's not cool...). If we meet some
* day, and you think this stuff is worth it, you can buy me a <del>beer</del> soda
* in return.
* Phyks (webmaster@phyks.me) wrote this file. As long as you retain this notice
* you can do whatever you want with this stuff (and you can also do whatever
* you want with this stuff without retaining it, but that's not cool...). If we
* meet some day, and you think this stuff is worth it, you can buy me a
* <del>beer</del> soda in return.
* Phyks
* ---------------------------------------------------------------------------------
* ------------------------------------------------------------------------------

View File

@ -1,9 +1,22 @@
#!/usr/bin/python
#!/usr/bin/env python3
# TODO : What happens when a file is moved with git ?
# TODO : Test the whole thing
# TODO : What happens when I run it as a hook ?
# TODO : What happens when I commit with -a option ?
# Blogit script written by Phyks (Lucas Verney) for his personnal use. I
# distribute it with absolutely no warranty, except that it works for me on my
# blog :)
# This script is a pre-commit hook that should be placed in your .git/hooks
# folder to work. Read README file for more info.
# LICENSE :
# -----------------------------------------------------------------------------
# "THE NO-ALCOHOL BEER-WARE LICENSE" (Revision 42):
# Phyks (webmaster@phyks.me) wrote this file. As long as you retain this notice
# you can do whatever you want with this stuff (and you can also do whatever
# you want with this stuff without retaining it, but that's not cool...). If
# we meet some day, and you think this stuff is worth it, you can buy me a
# <del>beer</del> soda in return.
# Phyks
# ----------------------------------------------------------------------------
import sys
import getopt
@ -17,11 +30,18 @@ import locale
from time import gmtime, strftime, mktime
# =========
# Functions
# =========
# Test if a variable exists (== isset function in PHP)
# ====================================================
def isset(variable):
return variable in locals() or variable in globals()
# Test wether a variable is an int or not
# =======================================
def isint(variable):
try:
int(variable)
@ -33,6 +53,7 @@ def isint(variable):
# List all files in path directory
# Works recursively
# Return files list with path relative to current dir
# ===================================================
def list_directory(path):
fichier = []
for root, dirs, files in os.walk(path):
@ -42,6 +63,7 @@ def list_directory(path):
# Return a list with the tags of a given article
# ==============================================
def get_tags(filename):
try:
with open(filename, 'r') as fh:
@ -61,6 +83,7 @@ def get_tags(filename):
#Return date of an article
# ========================
def get_date(filename):
try:
with open(filename, 'r') as fh:
@ -72,7 +95,8 @@ def get_date(filename):
sys.exit("[ERROR] Unable to open file "+filename+".")
# Return the number latest articles in dir directory
# Return the _number_ latest articles in _dir_ directory
# ======================================================
def latest_articles(directory, number):
try:
latest_articles = subprocess.check_output(["git",
@ -90,6 +114,7 @@ def latest_articles(directory, number):
# Auto create necessary directories to write a file
# =================================================
def auto_dir(path):
directory = os.path.dirname(path)
try:
@ -101,6 +126,7 @@ def auto_dir(path):
# Replace some user specific syntax tags (to repplace smileys for example)
# ========================================================================
def replace_tags(article, search_list, replace_list):
return_string = article
for search, replace in zip(search_list, replace_list):
@ -111,6 +137,10 @@ def replace_tags(article, search_list, replace_list):
# Set locale
locale.set_locale(locale.LC_ALL, '')
# ========================
# Start of the main script
# ========================
try:
opts, args = getopt.gnu_getopt(sys.argv, "hf", ["help", "force-regen"])
except getopt.GetoptError: