Compare commits

..

No commits in common. "master" and "refactor" have entirely different histories.

16 changed files with 259 additions and 1129 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
*~
*.swp
blog/

11
LICENSE Normal file
View File

@ -0,0 +1,11 @@
/*
* --------------------------------------------------------------------------------
* "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 --beer-- soda in
* return.
* Phyks
* ---------------------------------------------------------------------------------
*/

133
README.md
View File

@ -1,114 +1,53 @@
Blogit
======
This script aims at building a static blog above a git repo. This way, you can
use git abilities to have full archives and backups of your blog. Many scripts
aims at doing this, and this is just one more. I needed something more personal
and fitted to my needs, so I came up with this code. It's not very beautiful,
can mostly be optimized but it's working for me. It may not be fitted to your
needs, but it's up to you to see it.
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 script is just a python script that should be run as a git hook. You can
see a working version at http://phyks.me and the repository behind it is
publicly viewable at http://git.phyks.me/Blog. You should browse this
repository for example configuration and usage if you are interested by this
script.
This project is still a WIP.
This script has been developped by Phyks (phyks@phyks.me). For any suggestion
or remark, please send me an e-mail.
How it works ?
==============
## Installation
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.
1. Clone this repo.
2. Clear the .git directory and initialize a new empty git repo to store your
blog.
3. Move the `pre-commit.py` script to `.git/hooks/pre-commit`
4. Edit the `raw/params` and edit it to fit your needs.
5. The `raw` folder comes with an example of blog architecture. Delete it and
make your own.
6. You are ready to go !
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.
## Params
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).
Available options in `raw/params` are :
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).
* `BLOG_TITLE` : The title of the blog, to display in the <title> element
in rendered pages.
* `NB_ARTICLES_INDEX` : Number of articles to display on index page.
* `BLOG_URL` : Your blog base URL.
* `IGNORE_FILES` : A comma-separated list of files to ignore.
* `WEBMASTER` : Webmaster e-mail to put in RSS feed.
* `LANGUAGE` : Language param to put in RSS feed.
* `DESCRIPTION` : Blog description, for the RSS feed.
* `COPYRIGHT` : Copyright information, for the RSS feed.
* `SEARCH` : comma-separated list of elements to search for and replaced
(custom regex, see code for more info)
* `REPLACE` : corresponding elements for replacement.
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.
## Usage
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.
This script will use three folders:
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.
* `raw/` will contain your raw files
* `blog/` will contain the fully generated files to serve _via_ your http
server
* `gen/` will store temporary intermediate files
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 ^^).
All the files you have to edit are located in the `raw/` folder. It contains by
default an example version of a blog. You should start by renaming it and
making your own.
Example of syntax for an article
================================
```HTML
<!--
@tags=*** //put here the tags for your article, comma-separated list
@titre=***i //Title for your article
@author=Phyks //Name of the author (not displayed by now)
@date=23062013-1337 //Date in the format DDMMYYYY-HHMM
->
<article content> (== Whatever you want)</article>
```
Articles can be edited in HTML directly or in Markdown. They must be located in
a `raw/year/month` folder, according to their date of publication and end with
.html for html articles and .md for markdown articles. The basic content of an
article is: ```` <!-- @author=AUTHOR_NAME @date=DDMMYYYY-HHMM @title=TITLE
@tags=TAGS --> CONTENT ````
where TAGS is a comma-separated list. Tags are automatically created if they do
not exist yet. The HTML comment *must* be at the beginning of the document and
is parsed to set the metadata of the article.
CONTENT is then either a HTML string or a markdown formatted one.
You can ignore an article to not make it publicly visible during redaction,
simply by adding a .ignore extension.
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.
When you finish editing your article, you can add the files to git and commit,
to launch the script. You can also manually call the script with the
`--force-regen` option if you want to rebuild your entire blog.
## Header file
You can use the `@blog_url` syntax anywhere. It will be replaced by the URL of
the blog, as defined in the parameters (and this is useful to include CSS
etc.).
You can also use `@tags` that will be replaced by the list of tags and
`@articles` for the list of last articles.
## Static files
In static files, in raw folder (such as `divers.html` in the demo code), you
can use `#base_url` that will be replaced by the base url of the blog, as
defined in the parameters. This is useful to make some links.
## Alternatives
There exist many alternatives to this script, but they didn't fit my needs (and
were not all tested) :
* fugitive : http://shebang.ws/fugitive-readme.html
* Jekyll : http://jekyllrb.com/ and Oktopress : http://octopress.org/
* Blogofile : http://www.blogofile.com/
## 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
---------------------------------------------------------------------------------
* --------------------------------------------------------------------------------
* "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
* ---------------------------------------------------------------------------------

View File

@ -1,87 +0,0 @@
#!/usr/bin/env python3
from bs4 import BeautifulSoup
from bs4.element import Comment
import os
import base64
import hashlib
import hmac
import requests
import sys
"""
Script to import articles from a blogit blog in Known.
Must be run with a correct API_KEY (see below) and from the `gen/` folder.
"""
def list_directory(path):
fichier = []
for root, dirs, files in os.walk(path):
for i in files:
fichier.append(os.path.join(root, i))
return fichier
def hmac_sha256(message, key):
return base64.b64encode(hmac.new(key.encode("utf-8"),
message.encode("utf-8"),
digestmod=hashlib.sha256)
.digest()).decode("utf-8")
def known_api(username, api_key, type, payload):
headers = {
"X-KNOWN-USERNAME": username,
"X-KNOWN-SIGNATURE": hmac_sha256("/"+type+"/edit", api_key)
}
return requests.post("https://known.phyks.me/"+type+"/edit",
data=payload,
headers=headers)
if len(sys.argv) < 3:
print("Usage: "+sys.argv[0]+" USERNAME API_KEY [file]")
sys.exit()
API_USERNAME = sys.argv[1]
API_KEY = sys.argv[2]
if len(sys.argv) <= 3:
files = [list_directory(i) for i in ["2013", "2014", "2015"]]
else:
files = [sys.argv[3]]
for file in files:
print("Processing file "+file)
with open(file, 'r') as fh:
soup = BeautifulSoup(fh.read())
content = []
for i in soup.div.find('header').next_siblings:
if i.name == "footer":
break
if type(i) != Comment:
content.append(i)
comment = soup.div.findAll(text=lambda text: isinstance(text,
Comment))
comment = [i.strip() for i in comment[0].strip().split('\n')]
for j in comment:
if j.startswith("@title"):
title = j.split("=")[1]
elif j.startswith("@date"):
date = j.split("=")[1]
elif j.startswith("@tags"):
tags = j.split("=")[1]
tags = ', '.join(["#"+i.strip() for i in tags.split(',')])
meta = {
"title": title,
"date": (str(date[4:8])+":"+str(date[2:4])+":"+str(date[0:2]) +
" "+str(date[9:11])+":"+str(date[11:13])+":00"),
"tags": tags,
}
content = ''.join([str(i) for i in content]).strip()
content += "\n<p>"+meta["tags"]+"</p>"
payload = {"body": content,
"title": meta["title"],
"created": meta["date"]}
known_api(API_USERNAME, API_KEY, "entry", payload)

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
@title=Un exemple d'article
@tags=test
-->
<p>1Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>

View File

@ -1,29 +0,0 @@
#include_header_here
<article>
<aside class="aside_article">
<p class="month">Phyks</p>
</aside>
<div class="article">
<h1 class="article_title">Contact</h1>
<h2>E-mail</h2>
<p>[FR] Vous pouvez me contacter par e-mail à l'adresse suivante (pseudo@domaine.me) :</p>
<p>[EN] You can contact me using the following e-mail address (nick@domain.me) :</p>
<p class="center"><span class="contact_e-mail">@</span></p>
<h2>Jabber</h2>
<p>[FR] Vous pouvez également me joindre sur Jabber :</p>
<p>[EN] I'm also available very often on Jabber :</p>
<p class="center"><span class="contact_e-mail">@</span></p>
<h2>Divers</h2>
<ul>
<li>Mon <a href="https://github.com/phyks/">profil Github</a>.</li>
<li>[FR] Tous les codes que j'écris et les articles de ce blog sont sous licence <em>BEERWARE</em> (sauf mention contraire). Vous êtes libres de faire tout ce que vous voulez avec. Si vous souhaitez me soutenir, le meilleur moyen reste de liartager ces informations autour de vous (et de citer la source :). Vous liouvez également me liayer <del>une bière</del> un soda <em>via</em> Flattr ou tout autre moyen qui vous convient.</li>
<li>[EN] All my source codes and articles on my blog are under a <em>BEERWARE</em> license (except if anything special is specified). You are free to do whatever you want with them. If you want to support me, the best way is to share these pieces of information around you (and to cite the source :). You can also pay me a <del>beer</del> soda <em>via</em> Flattr or any mean you want.</li>
</ul>
</div>
</article>
#include_footer_here

View File

@ -1,291 +0,0 @@
html, body {
margin: 0;
padding: 0;
background-color: rgb(35, 34, 34);
background-image: url('img/bg.png');
font-family: "DejaVu Sans", Verdana, "Bitstream Vera Sans", Geneva, sans-serif;
line-height: 1.5em;
text-align: justify;
}
/* General classes */
.monospace {
font-family: "Lucida Console", Monaco, monospace;
}
.center {
text-align: center;
}
.contact_e-mail:before {
unicode-bidi: bidi-override;
direction: rtl;
content: "em.skyhp";
}
.contact_e-mail:after {
unicode-bidi: bidi-override;
direction: rtl;
content: "skyhp";
}
/* Wrapper */
#wrapper {
padding-left: 17em;
transition: all 0.4s ease 0s;
}
/* Hide the header and display it only in responsive view */
#header {
display: none;
text-align: center;
width: 50%;
margin: auto;
font-size: 0.9em;
padding: 0.3em;
}
#header h1 {
font-weight: normal;
padding: 0;
margin: 0;
margin-top: 0.5em;
background-color: rgb(117, 170, 39);
background-image: url("img/sidebar.png");
border: 1px solid black;
border-radius: 0.2em;
padding: 0.6em;
}
#header a {
color: white;
text-decoration: none;
}
/* Sidebar */
#sidebar-wrapper {
margin-left: -16em;
position: fixed;
left: 16em;
width: 16em;
height: 100%;
background: url('img/sidebar.png') repeat scroll 0% 0% rgb(17, 78, 121);
overflow-y: auto;
transition: all 0.4s ease 0s;
color: white;
padding-left: 0.5em;
padding-right: 0.5em;
font-size: 0.9em;
z-index: 1000;
}
#sidebar-wrapper a {
color: white;
}
#sidebar-wrapper h2 {
font-weight: normal;
text-align: center;
margin: 0.5em;
}
#sidebar-title {
font-size: 2em;
margin-top: 0.5em;
padding: 0.7em 0.5em;
background-color: rgb(117, 170, 39);
background-image: url("img/sidebar.png");
border-radius: 0.2em;
font-weight: normal;
text-align: center;
border: 1px solid black;
}
#sidebar-title a {
text-decoration: none;
}
#sidebar-tags {
text-align: center;
}
#sidebar-tags .tag {
display: inline;
}
#sidebar-tags .tag img {
width: 20%;
max-width: 4em;
margin: 0.5em 0.5em 1.5em;
}
#sidebar-tags .tag .popup {
position: absolute;
margin-left: -35%;
word-wrap: break-word;
width: 33%;
margin-top: 1em;
color: rgb(117, 170, 39);
background: none repeat scroll 0% 0% rgba(0, 0, 0, 0.9);
padding: 1em;
border-radius: 3px;
box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5);
opacity: 0;
text-align: center;
transform: scale(0) rotate(-12deg);
transition: all 0.25s ease 0s;
}
#sidebar-tags .tag:hover .popup, #sidebar-tags .tag:focus .popup
{
transform: scale(1) rotate(0);
opacity: 0.8;
}
#sidebar-articles {
opacity: 0.7;
text-align: center;
list-style-type: none;
padding: 0;
}
#sidebar-links {
list-style-type: none;
text-align: center;
padding: 0;
}
#sidebar-links li {
background-color: rgb(117, 170, 39);
background-image: url("img/sidebar.png");
text-align: right;
margin-right: 2em;
padding-right: 1em;
margin-bottom: 1em;
margin-left: -0.5em;
height: 2em;
border-top-right-radius: 0.7em;
border-bottom-right-radius: 0.7em;
border: 1px solid black;
transition: all 0.4s ease 0s;
}
#sidebar-links li:hover {
transform: scale(1.1);
}
/* Articles */
article {
max-width: 70em;
margin: auto;
}
.article {
background-color: white;
margin-left: 4.5em;
padding: 1.3em;
position: relative;
margin-bottom: 3em;
min-height: 5.48em;
}
#articles article:last-child {
margin-bottom: 0;
}
#articles h1, #articles h2, #articles h3, #articles h4, #articles h5 {
font-family: "Lucida Console", Monaco, monospace;
font-weight: normal;
}
article .article_title {
text-align: center;
margin-top: 0.1em;
margin-bottom: 1.5em;
}
#articles {
width: calc(100% - 1.5em);
padding-top: 1.5em;
}
#articles h1 {
margin: 0;
}
.aside_article {
position: absolute;
background-color: white;
font-size: 1.5em;
height: 4.5em;
padding: 0 0.5em;
-webkit-transform-origin: 100% 0;
-webkit-transform: translateX(-100%) translateY(1.2em) rotate(-90deg);
transform-origin: 100% 0;
transform: translateX(-100%) translateY(1.2em) rotate(-90deg);
}
.aside_article p {
display: block;
}
.aside_article .day {
float: right;
margin-bottom: 0.3em;
margin-top: 0.4em;
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
width: 100%;
text-align: center;
}
#articles .date {
font-size: 0.8em;
font-style: italic;
text-align: right;
margin: 0;
}
.archives {
text-align: center;
color: white;
}
.archives a {
color: white;
}
/* Media queries */
@media (max-width: 767px) {
#wrapper {
padding-left: 1.5em;
}
#sidebar-wrapper {
left: 0;
}
#sidebar-wrapper:hover {
left: 16em;
width: 16em;
transition: all 0.4s ease 0s;
}
#sidebar-title {
display: none;
}
}
@media (max-width: 600px) {
.aside_article {
display: none;
}
.article {
margin-left: auto;
}
#header {
display: block;
}
}

View File

@ -1,18 +0,0 @@
#include_header_here
<article>
<aside class="aside_article">
<p class="month">Divers</p>
</aside>
<div class="article">
<h1 class="article_title">Liens divers</h1>
<ul>
<li><a href="#base_url/pub/">Divers documents en vrac</a></li>
<li><a href="#base_url/pub/respawn">Mon respawn</a></li>
<li><a href="http://git.phyks.me">Mon dépôt Git, alternatif à Github</a></li>
<li><a href="#base_url/autohebergement.html">Ma doc sur l'autohébergement</a></li>
<li><a href="http://snippet.phyks.me">Mes snippets</a></li>
<li><a href="http://velib.phyks.me">Ma webapp vélib</a> (cf <a href="https://github.com/phyks/BikeInParis">le projet sur Github</a>)</li>
</ul>
</div>
</article>
#include_footer_here

View File

@ -1,4 +1,4 @@
</div>
</div>
</body>
</div>
</div>
</body>
</html>

View File

@ -1,41 +1,30 @@
<!DOCTYPE html>
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>@title</title>
<link rel="stylesheet" href="design.css"/>
<link type="text/plain" rel="author" href="humans.txt"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="wrapper">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<h1 id="sidebar-title"><a href="@blog_url">~Phyks</a></h1>
<h2>Catégories</h2>
<nav id="sidebar-tags">
@tags
</nav>
<h2>Derniers articles</h2>
<ul id="sidebar-articles">
@articles
</ul>
<h2>Liens</h2>
<ul id="sidebar-links">
<li><a href="contact.html" title="Contact">Me contacter</a></li>
<li class="monospace"><a href="//links.phyks.me" title="Mon Shaarli">find ~phyks -type l</a></li>
<li><a href="https://github.com/phyks/" title="Github">Mon Github</a></li>
<li><a href="divers.html" title="Divers">Divers</a></li>
</ul>
</div>
<!-- Page content -->
<div id="header">
<h1><a href="@blog_url">~Phyks</a></h1>
</div>
<div id="articles">
<head>
<meta charset="utf-8">
<title>@titre</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="wrapper">
<div id="left">
<h1 id="head_title">Phyks' Blog</h1>
<hr/><hr/>
<h2>Catégories</h2>
<div id="categories">
@categories
</div>
<hr/>
<h2>Derniers articles</h2>
<div id="last_articles">
@articles
</div>
<hr/>
<h2>Liens</h2>
<ul class="links">
<li><a href="contact.html">Me contacter</a></li>
<li><a href="http://links.phyks.me">Mon shaarli</a></li>
<li><a href="http://projet.phyks.me">Mes projets</a></li>
</ul>
</div>
<div id="articles">

View File

@ -1,11 +0,0 @@
/* AUTHOR */
Phyks (Lucas Verney)
Website : http://phyks.me
Send me an e-mail : phyks@phyks.me
Or contact me on jabber : phyks@phyks.me
Or meet me on github : https://github.com/phyks/
/* SITE */
Last update: 2013/09/15
Standards: HTML5, CSS3 (valid)
Software: Only open-source software :)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

View File

@ -1,12 +1,9 @@
BLOG_TITLE = Blog
BLOG_TITLE = Phyks' blog
NB_ARTICLES_INDEX = 20
BLOG_URL = #BLOG_URL
PROTOCOL = http
IGNORE_FILES =
BLOG_URL = file:///home/lucas/Blog/git/blog/
#RSS params
WEBMASTER = #EMAIL_URL
WEBMASTER = webmaster@phyks.me (Phyks)
LANGUAGE = fr
DESCRIPTION =
COPYRIGHT =

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB