Skip to content

Instantly share code, notes, and snippets.

@zunction
Forked from JosefJezek/how-to-use-pelican.md
Created January 19, 2016 05:32
Show Gist options
  • Save zunction/199f788bb56985c88c7b to your computer and use it in GitHub Desktop.
Save zunction/199f788bb56985c88c7b to your computer and use it in GitHub Desktop.

Revisions

  1. @JosefJezek JosefJezek revised this gist Jul 26, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -63,8 +63,6 @@ git config --global user.email [email protected]
    git config --global core.editor vi
    ```



    ### Clone git repository

    ```
    @@ -79,6 +77,7 @@ Create in the root folder a file `.gitignore`
    ```
    #Custom
    output
    pelicanconf_local.py
    #Python
    *.py[cod]
  2. @JosefJezek JosefJezek revised this gist Jul 25, 2013. 1 changed file with 9 additions and 12 deletions.
    21 changes: 9 additions & 12 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -55,18 +55,15 @@ sudo pip install --upgrade pelican markdown ghp-import shovel

    We need to make a respository. For example blog, so our blog url will be `user.github.com/blog`. If you want to set a custom domain see link: [Setting up a custom domain with Pages](https://help.github.com/articles/setting-up-a-custom-domain-with-pages)

    ### Steps to publish a post

    In parenthesis is the git branch we are working on:

    1. (`master`) Create the post in rst or md (rst and md are abbreviations for resTructuredText and markdown)
    2. (`master`) Generate the HTML
    3. (`master`) Check the post in a local server
    4. (`master`) We could delete the output but dones't matter if we don't because git will ignore with our gitignore file
    5. (`gh-pages`) Merge master branch
    6. (`gh-pages`) Generate the HTML
    7. (`gh-pages`) push all the files (normally all the new HTML)
    8. (`master`) push all the files (normally only one post)
    ### Prepare git

    ```
    git config --global user.name "John Doe"
    git config --global user.email [email protected]
    git config --global core.editor vi
    ```



    ### Clone git repository

  3. @JosefJezek JosefJezek revised this gist Jul 25, 2013. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -131,13 +131,13 @@ git clone --recursive https://github.com/getpelican/pelican-themes themes

    ### Create Pelican settings file

    Create settings file called `shovelconf.py` from sample `pelican.conf.py`
    Create settings file called `pelicanconf.py` from sample `pelican.conf.py`

    ```
    wget -O shovelconf.py https://raw.github.com/getpelican/pelican/master/samples/pelican.conf.py
    wget -O pelicanconf.py https://raw.github.com/getpelican/pelican/master/samples/pelican.conf.py
    ```

    Add this variables
    Add this variables

    ```
    THEME = 'themes/bootstrap2'
    @@ -154,7 +154,7 @@ ARTICLE_SAVE_AS = 'posts/{date:%Y}/{date:%m}/{slug}/index.html'

    ### Custom Home page

    Add this variables to `shovelconf.py`
    Add this variables to `pelicanconf.py`

    ```
    # Custom Home page
    @@ -208,13 +208,13 @@ This is the content of my blog post.
    To generate the static html we use:

    ```
    pelican -s shovelconf.py
    pelican -s pelicanconf.py
    ```

    This will take all the settings and apply, but if we want to override some settings we could do. For example to specify the ouput we use `-o`:

    ```
    pelican -s shovelconf.py -o /tmp/blog
    pelican -s pelicanconf.py -o /tmp/blog
    ```

    Issues
  4. @JosefJezek JosefJezek revised this gist Jul 25, 2013. 1 changed file with 8 additions and 52 deletions.
    60 changes: 8 additions & 52 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -131,18 +131,18 @@ git clone --recursive https://github.com/getpelican/pelican-themes themes

    ### Create Pelican settings file

    Create settings file called `settings.py` from sample `pelican.conf.py`
    Create settings file called `shovelconf.py` from sample `pelican.conf.py`

    ```
    wget -O settings.py https://raw.github.com/getpelican/pelican/master/samples/pelican.conf.py
    wget -O shovelconf.py https://raw.github.com/getpelican/pelican/master/samples/pelican.conf.py
    ```

    Add this variables

    ```
    THEME = 'themes/bootstrap2'
    OUTPUT_PATH = 'output'
    PATH = 'src'
    PATH = 'content'
    ```

    Period archives work best when the final path segment is `index.html`, see [URL Settings](http://docs.getpelican.com/en/latest/settings.html#url-settings)
    @@ -154,7 +154,7 @@ ARTICLE_SAVE_AS = 'posts/{date:%Y}/{date:%m}/{slug}/index.html'

    ### Custom Home page

    Add this variables to `settings.py`
    Add this variables to `shovelconf.py`

    ```
    # Custom Home page
    @@ -187,8 +187,8 @@ Create `home.html` or use [page override](http://docs.getpelican.com/en/latest/f
    ### Creating post

    ```
    mkdir -p src/posts/2013/07
    vi src/posts/2013/07/welcome-all.md
    mkdir -p content/posts/2013/07
    vi content/posts/2013/07/welcome-all.md
    ```

    ```
    @@ -208,13 +208,13 @@ This is the content of my blog post.
    To generate the static html we use:

    ```
    pelican -s settings.py
    pelican -s shovelconf.py
    ```

    This will take all the settings and apply, but if we want to override some settings we could do. For example to specify the ouput we use `-o`:

    ```
    pelican -s settings.py -o /tmp/blog
    pelican -s shovelconf.py -o /tmp/blog
    ```

    Issues
    @@ -234,51 +234,7 @@ Point your browser to `localhost:8000` and you will see the blog.

    ### Deploying the blog

    We start the process in the `master` branch:

    ```
    git add .
    git commit -m "First post: Welcome All"
    ```

    Push it to master (remember, this doesn't deploy the page, this is our source):

    ```
    git push origin master
    ```

    If we havent the gh-pages branch we create:

    ```
    git branch gh-pages
    ```

    Change to gh-pages and merge the master branch:

    ```
    git checkout gh-pages
    git merge master
    ```

    Now generate the HTML. But wait! github doesn't know that our webpage is in output dir, so we need to put our generated HTML in the root of the project, to do that we replace the settings outputdir in the command:

    ```
    pelican -s local_settings.py -o ./
    ```

    We are ready to deploy, commit all and push:

    ```
    git add .
    git commit -m "Publish Welcome All post"
    git push origin gh-pages
    ```

    We change again to our master branch and we are done :):

    ```
    git checkout master
    ```

    Point your browser to you.github.com/blog , Awesome!!!

  5. @JosefJezek JosefJezek revised this gist Jul 25, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ Author: [Josef Jezek](http://about.me/josefjezek)
    ```
    sudo apt-get install python-setuptools
    sudo easy_install pip
    sudo pip install virtualenv virtualenvwrapper ghp-import
    sudo pip install virtualenv virtualenvwrapper
    ```

    `vi ~/.bashrc` (maybe `virtualenvwrapper.sh` is in other location, change if necessary)
    @@ -42,13 +42,13 @@ deactivate
    ### Installing Pelican

    ```
    sudo pip install pelican markdown
    sudo pip install pelican markdown ghp-import shovel
    ```

    ### Upgrading Pelican

    ```
    sudo pip install --upgrade pelican markdown
    sudo pip install --upgrade pelican markdown ghp-import shovel
    ```

    ## Creating a blog on [GitHub Pages](https://help.github.com/categories/20/articles/)
  6. @JosefJezek JosefJezek revised this gist Jul 24, 2013. 1 changed file with 1 addition and 110 deletions.
    111 changes: 1 addition & 110 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ Author: [Josef Jezek](http://about.me/josefjezek)
    ```
    sudo apt-get install python-setuptools
    sudo easy_install pip
    sudo pip install virtualenv virtualenvwrapper fabric
    sudo pip install virtualenv virtualenvwrapper ghp-import
    ```

    `vi ~/.bashrc` (maybe `virtualenvwrapper.sh` is in other location, change if necessary)
    @@ -282,116 +282,7 @@ git checkout master

    Point your browser to you.github.com/blog , Awesome!!!

    ### Automation

    [Fabric](http://fabfile.org) is a tool, an awesome tool! to automate things, is most used for remote servers, but also works fine for local automation. Put `fabfile.py` in the root path of the blog in the `master branch`.

    Now you can use like this:

    * `fab generate`: generates the html for developing (while writing)
    * `fab serve`: Serves the blog in local
    * `fab publish`: Does all the process of change, commit and publish gh-pages branch, needs to be in `master branch` while executing the command

    `vi fabfile.py`

    ```python
    import os
    import time

    from fabric.api import local, lcd, settings
    from fabric.utils import puts
    from settings import OUTPUT_PATH

    SETTINGS_FILE = "settings.py"

    # Get directories
    ABS_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
    ABS_SETTINGS_FILE = os.path.join(ABS_ROOT_DIR, SETTINGS_FILE)
    ABS_OUTPUT_PATH = os.path.join(ABS_ROOT_DIR, OUTPUT_PATH)


    # Commands
    def generate(output=None):
    """Generates the pelican static site"""

    if not output:
    cmd = "pelican -s {0}".format(ABS_SETTINGS_FILE)
    else:
    cmd = "pelican -s {0} -o {1}".format(ABS_SETTINGS_FILE, output)

    local(cmd)


    def destroy(output=None):
    """Destroys the pelican static site"""

    if not output:
    cmd = "rm -r {0}".format(os.path.join(ABS_ROOT_DIR, OUTPUT_PATH))
    else:
    cmd = "rm -r {0}".format(output)

    with settings(warn_only=True):
    result = local(cmd)
    if result.failed:
    puts("Already deleted")


    def serve():
    """Serves the site in the development webserver"""
    print(ABS_OUTPUT_PATH)
    with lcd(ABS_OUTPUT_PATH):
    local("python -m SimpleHTTPServer")


    def git_change_branch(branch):
    """Changes from one branch to other in a git repo"""
    local("git checkout {0}".format(branch))


    def git_merge_branch(branch):
    """Merges a branch in other branch"""
    local("git merge {0}".format(branch))


    def git_push(remote, branch):
    """Pushes the git changes to git remote repo"""
    local("git push {0} {1}".format(remote, branch))


    def git_commit_all(msg):
    """Commits all the changes"""
    local("git add .")
    local("git commit -m \"{0}\"".format(msg))


    def publish():
    """Generates and publish the new site in github pages"""
    master_branch = "master"
    publish_branch = "gh-pages"
    remote = "origin"

    # Push original changes to master
    #push(remote, master_branch)

    # Change to gh-pages branch
    git_change_branch(publish_branch)

    # Merge master into gh-pages
    git_merge_branch(master_branch)

    # Generate the html
    generate(ABS_ROOT_DIR)

    # Commit changes
    now = time.strftime("%d %b %Y %H:%M:%S", time.localtime())
    git_commit_all("Publication {0}".format(now))

    # Push to gh-pages branch
    git_push(remote, publish_branch)

    # go to master
    git_change_branch(master_branch)
    ```

    ## Resources

  7. @JosefJezek JosefJezek revised this gist Jul 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ sudo easy_install pip
    sudo pip install virtualenv virtualenvwrapper fabric
    ```

    `vi ~/.bashrc` (maybe virtualenvwrapper.sh is in other location, change if necessary)
    `vi ~/.bashrc` (maybe `virtualenvwrapper.sh` is in other location, change if necessary)

    ```sh
    # Virtualenvwrapper
  8. @JosefJezek JosefJezek revised this gist Jul 24, 2013. 1 changed file with 35 additions and 1 deletion.
    36 changes: 35 additions & 1 deletion how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -152,6 +152,38 @@ ARTICLE_URL = 'posts/{date:%Y}/{date:%m}/{slug}/'
    ARTICLE_SAVE_AS = 'posts/{date:%Y}/{date:%m}/{slug}/index.html'
    ```

    ### Custom Home page

    Add this variables to `settings.py`

    ```
    # Custom Home page
    DIRECT_TEMPLATES = (('index', 'blog', 'tags', 'categories', 'archives'))
    PAGINATED_DIRECT_TEMPLATES = (('blog',))
    TEMPLATE_PAGES = {'home.html': 'index.html',}
    ```

    Duplicated the `index.html` to `blog.html` in your template folder and add this lines:

    ```
    {% set active_page = "blog" %}
    {% block title %}{{ SITENAME }} - Blog{% endblock %}
    ```

    Create `home.html` or use [page override](http://docs.getpelican.com/en/latest/faq.html#how-can-i-use-a-static-page-as-my-home-page) feature to use a Markdown page as your home page.

    `vi home.html`

    ```
    {% extends "base.html" %}
    {% block content %}
    <div class='page'>
    <div class="page-header"><h1>Home</h1></div>
    <div class="page-content">Content</div>
    </div>
    {% endblock %}
    ```

    ### Creating post

    ```
    @@ -365,4 +397,6 @@ def publish():

    * http://blog.xlarrakoetxea.org/posts/2012/10/creating-a-blog-with-pelican
    * http://docs.getpelican.com/en/latest/getting_started.html
    * http://docs.getpelican.com/en/latest/tips.html#publishing-to-github
    * http://docs.getpelican.com/en/latest/tips.html#publishing-to-github
    * http://raichev.net/blohg-to-pelican.html
    * https://github.com/getpelican/pelican/issues/735#issuecomment-17674540
  9. @JosefJezek JosefJezek revised this gist Jul 23, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -168,8 +168,6 @@ Tags: pelican, publishing
    Author: Josef Jezek
    Summary: Short version for index and feeds
    # Welcome All
    This is the content of my blog post.
    ```

  10. @JosefJezek JosefJezek revised this gist Jul 23, 2013. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -4,12 +4,12 @@ Author: [Josef Jezek](http://about.me/josefjezek)

    ## Install on Ubuntu

    ### Installing Pelican with Python tools
    ### Installing Python tools

    ```
    sudo apt-get install python-setuptools
    sudo easy_install pip
    sudo pip install pelican markdown fabric virtualenv virtualenvwrapper
    sudo pip install virtualenv virtualenvwrapper fabric
    ```

    `vi ~/.bashrc` (maybe virtualenvwrapper.sh is in other location, change if necessary)
    @@ -39,10 +39,16 @@ And to leave
    deactivate
    ```

    ### Installing Pelican

    ```
    sudo pip install pelican markdown
    ```

    ### Upgrading Pelican

    ```
    pip install --upgrade pelican markdown
    sudo pip install --upgrade pelican markdown
    ```

    ## Creating a blog on [GitHub Pages](https://help.github.com/categories/20/articles/)
  11. @JosefJezek JosefJezek revised this gist Jul 23, 2013. 1 changed file with 6 additions and 14 deletions.
    20 changes: 6 additions & 14 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -75,7 +75,6 @@ Create in the root folder a file `.gitignore`

    ```
    #Custom
    local_settings.py
    output
    #Python
    @@ -126,17 +125,16 @@ git clone --recursive https://github.com/getpelican/pelican-themes themes

    ### Create Pelican settings file

    Now we will create a pelican settings file called `local_settings.py`, this file will not be commited to the git repo, maybe has personal data. But we will upload a blank template named `settings.py`, so we create also this one, that has the same variables as `local_settings.py` but without the vars data. Edit the data you need (You can store the `local_settings.py` data in a private gist manually):
    Create settings file called `settings.py` from sample `pelican.conf.py`

    ```
    wget -O settings.py https://raw.github.com/getpelican/pelican/master/samples/pelican.conf.py
    cp settings.py local_settings.py
    ```

    Add this variables

    ```
    THEME = 'themes/bootstrap'
    THEME = 'themes/bootstrap2'
    OUTPUT_PATH = 'output'
    PATH = 'src'
    ```
    @@ -174,13 +172,13 @@ This is the content of my blog post.
    To generate the static html we use:

    ```
    pelican -s local_settings.py
    pelican -s settings.py
    ```

    This will take all the settings and apply, but if we want to override some settings we could do. For example to specify the ouput we use `-o`:

    ```
    pelican -s local_settings.py -o /tmp/myBlog
    pelican -s settings.py -o /tmp/blog
    ```

    Issues
    @@ -266,15 +264,9 @@ import time

    from fabric.api import local, lcd, settings
    from fabric.utils import puts
    from settings import OUTPUT_PATH

    #If no local_settings.py then settings.py
    try:
    from local_settings import OUTPUT_PATH
    SETTINGS_FILE = "local_settings.py"
    except ImportError:
    from settings import OUTPUT_PATH
    SETTINGS_FILE = "settings.py"

    SETTINGS_FILE = "settings.py"

    # Get directories
    ABS_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
  12. @JosefJezek JosefJezek revised this gist Jul 23, 2013. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -116,6 +116,14 @@ nosetests.xml
    .pydevproject
    ```

    ### Download Themes

    Clone `pelican-themes` repository

    ```
    git clone --recursive https://github.com/getpelican/pelican-themes themes
    ```

    ### Create Pelican settings file

    Now we will create a pelican settings file called `local_settings.py`, this file will not be commited to the git repo, maybe has personal data. But we will upload a blank template named `settings.py`, so we create also this one, that has the same variables as `local_settings.py` but without the vars data. Edit the data you need (You can store the `local_settings.py` data in a private gist manually):
    @@ -128,6 +136,7 @@ cp settings.py local_settings.py
    Add this variables

    ```
    THEME = 'themes/bootstrap'
    OUTPUT_PATH = 'output'
    PATH = 'src'
    ```
    @@ -174,6 +183,10 @@ This will take all the settings and apply, but if we want to override some setti
    pelican -s local_settings.py -o /tmp/myBlog
    ```

    Issues

    * `WARNING: LOCALE option doesn't contain a correct value` see [Ubuntu Locale](https://help.ubuntu.com/community/Locale)

    Then we have a new directory named `output`, our blog is there, so, to test it , insert there and run a simple server:

    ```
  13. @JosefJezek JosefJezek revised this gist Jul 23, 2013. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -66,7 +66,7 @@ In parenthesis is the git branch we are working on:

    ```
    git clone [email protected]:user/blog.git
    cd ./blog
    cd blog
    ```

    Create in the root folder a file `.gitignore`
    @@ -142,8 +142,8 @@ ARTICLE_SAVE_AS = 'posts/{date:%Y}/{date:%m}/{slug}/index.html'
    ### Creating post

    ```
    mkdir -p ./posts/2013/07
    vi welcome-all.md
    mkdir -p src/posts/2013/07
    vi src/posts/2013/07/welcome-all.md
    ```

    ```
    @@ -165,19 +165,19 @@ This is the content of my blog post.
    To generate the static html we use:

    ```
    pelican -s ./local_settings.py
    pelican -s local_settings.py
    ```

    This will take all the settings and apply, but if we want to override some settings we could do. For example to specify the ouput we use `-o`:

    ```
    pelican -s ./local_settings.py -o /tmp/myBlog
    pelican -s local_settings.py -o /tmp/myBlog
    ```

    Then we have a new directory named `output`, our blog is there, so, to test it , insert there and run a simple server:

    ```
    cd ./output
    cd output
    python -m SimpleHTTPServer 8000
    # For Python 3
    python -m http.server 8000
    @@ -216,7 +216,7 @@ git merge master
    Now generate the HTML. But wait! github doesn't know that our webpage is in output dir, so we need to put our generated HTML in the root of the project, to do that we replace the settings outputdir in the command:

    ```
    pelican -s ./local_settings.py -o ./
    pelican -s local_settings.py -o ./
    ```

    We are ready to deploy, commit all and push:
  14. @JosefJezek JosefJezek revised this gist Jul 23, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -245,7 +245,7 @@ Now you can use like this:
    * `fab serve`: Serves the blog in local
    * `fab publish`: Does all the process of change, commit and publish gh-pages branch, needs to be in `master branch` while executing the command

    The `fabfile.py`:
    `vi fabfile.py`

    ```python
    import os
  15. @JosefJezek JosefJezek revised this gist Jul 23, 2013. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -125,6 +125,20 @@ wget -O settings.py https://raw.github.com/getpelican/pelican/master/samples/pel
    cp settings.py local_settings.py
    ```

    Add this variables

    ```
    OUTPUT_PATH = 'output'
    PATH = 'src'
    ```

    Period archives work best when the final path segment is `index.html`, see [URL Settings](http://docs.getpelican.com/en/latest/settings.html#url-settings)

    ```
    ARTICLE_URL = 'posts/{date:%Y}/{date:%m}/{slug}/'
    ARTICLE_SAVE_AS = 'posts/{date:%Y}/{date:%m}/{slug}/index.html'
    ```

    ### Creating post

    ```
  16. @JosefJezek JosefJezek renamed this gist Jul 23, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions how-to-pelican.md → how-to-use-pelican.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # How to [Pelican](http://docs.getpelican.com) on [GitHub Pages](http://pages.github.com) [![Gittip](https://raw.github.com/gittip/www.gittip.com/master/img-src/gittip-logo-32.png)](https://www.gittip.com/josefjezek)
    # How to use [Pelican](http://docs.getpelican.com) on [GitHub Pages](http://pages.github.com) [![Gittip](https://raw.github.com/gittip/www.gittip.com/master/img-src/gittip-logo-32.png)](https://www.gittip.com/josefjezek)

    Author: [Josef Jezek](http://about.me/josefjezek)

    @@ -26,14 +26,14 @@ Load file `.bashrc`
    source ~/.bashrc
    ```

    Create virtualenv:
    Create [virtualenv](http://www.virtualenv.org/en/latest/) with [virtualenvwrapper](http://www.doughellmann.com/projects/virtualenvwrapper/)

    ```
    mkvirtualenv blog
    workon blog
    ```

    And to leave:
    And to leave

    ```
    deactivate
  17. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -69,7 +69,7 @@ git clone [email protected]:user/blog.git
    cd ./blog
    ```

    Create in the root folder a file named `.gitignore`
    Create in the root folder a file `.gitignore`

    `vi .gitignore`

    @@ -223,13 +223,13 @@ Point your browser to you.github.com/blog , Awesome!!!

    ### Automation

    [Fabric](http://fabfile.org) is a tool, an awesome tool! to automate things, is most used for remote servers, but also works fine for local automation. Put `fabfile.py` in the root path of the blog in the `master` branch.
    [Fabric](http://fabfile.org) is a tool, an awesome tool! to automate things, is most used for remote servers, but also works fine for local automation. Put `fabfile.py` in the root path of the blog in the `master branch`.

    Now you can use like this:

    * `fab generate`: generates the html for developing (while writing)
    * `fab serve`: Serves the blog in local
    * `fab publish`: Does all the process of change, commit and publish gh-pages branch, needs to be in master branch while executing the command
    * `fab publish`: Does all the process of change, commit and publish gh-pages branch, needs to be in `master branch` while executing the command

    The `fabfile.py`:

  18. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    # How to Pelican on GitHub Pages
    # How to [Pelican](http://docs.getpelican.com) on [GitHub Pages](http://pages.github.com) [![Gittip](https://raw.github.com/gittip/www.gittip.com/master/img-src/gittip-logo-32.png)](https://www.gittip.com/josefjezek)

    Author: [Josef Jezek](http://about.me/josefjezek)

    ## Install on Ubuntu

  19. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -130,7 +130,7 @@ mkdir -p ./posts/2013/07
    vi welcome-all.md
    ```

    ```markdown
    ```
    Title: Welcome All
    Slug: welcome-all
    Date: 2013-07-22 19:19
  20. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -5,12 +5,12 @@
    ### Installing Pelican with Python tools

    ```
    sudo apt-get install python-setuptools
    sudo easy_install pip
    sudo pip install pelican markdown fabric virtualenv virtualenvwrapper
    ```

    `vi ~/.bashrc`
    (maybe virtualenvwrapper.sh is in other location, change if necessary)
    `vi ~/.bashrc` (maybe virtualenvwrapper.sh is in other location, change if necessary)

    ```sh
    # Virtualenvwrapper
  21. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@ sudo pip install pelican markdown fabric virtualenv virtualenvwrapper
    ```

    `vi ~/.bashrc`
    (maybe virtualenvwrapper.sh is in other location, change if necessary)

    ```sh
    # Virtualenvwrapper
  22. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -59,9 +59,7 @@ In parenthesis is the git branch we are working on:
    7. (`gh-pages`) push all the files (normally all the new HTML)
    8. (`master`) push all the files (normally only one post)

    ### Create git repository

    Clone git repository
    ### Clone git repository

    ```
    git clone [email protected]:user/blog.git
  23. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 8 additions and 10 deletions.
    18 changes: 8 additions & 10 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -44,6 +44,8 @@ pip install --upgrade pelican markdown

    ## Creating a blog on [GitHub Pages](https://help.github.com/categories/20/articles/)

    We need to make a respository. For example blog, so our blog url will be `user.github.com/blog`. If you want to set a custom domain see link: [Setting up a custom domain with Pages](https://help.github.com/articles/setting-up-a-custom-domain-with-pages)

    ### Steps to publish a post

    In parenthesis is the git branch we are working on:
    @@ -113,7 +115,7 @@ nosetests.xml
    .pydevproject
    ```

    ### Create a Pelican settings file
    ### Create Pelican settings file

    Now we will create a pelican settings file called `local_settings.py`, this file will not be commited to the git repo, maybe has personal data. But we will upload a blank template named `settings.py`, so we create also this one, that has the same variables as `local_settings.py` but without the vars data. Edit the data you need (You can store the `local_settings.py` data in a private gist manually):

    @@ -122,14 +124,14 @@ wget -O settings.py https://raw.github.com/getpelican/pelican/master/samples/pel
    cp settings.py local_settings.py
    ```

    ### Creating a post
    ### Creating post

    ```
    mkdir -p ./posts/2013/07
    vi welcome-all.md
    ```

    ```md
    ```markdown
    Title: Welcome All
    Slug: welcome-all
    Date: 2013-07-22 19:19
    @@ -224,9 +226,9 @@ Point your browser to you.github.com/blog , Awesome!!!

    Now you can use like this:

    `fab generate`: generates the html for developing (while writing)
    `fab serve`: Serves the blog in local
    `fab publish`: Does all the process of change, commit and publish gh-pages branch, needs to be in master branch while executing the command
    * `fab generate`: generates the html for developing (while writing)
    * `fab serve`: Serves the blog in local
    * `fab publish`: Does all the process of change, commit and publish gh-pages branch, needs to be in master branch while executing the command

    The `fabfile.py`:

    @@ -335,10 +337,6 @@ def publish():
    git_change_branch(master_branch)
    ```

    ### Custom domain

    [Setting up a custom domain with Pages](https://help.github.com/articles/setting-up-a-custom-domain-with-pages)

    ## Resources

    * http://blog.xlarrakoetxea.org/posts/2012/10/creating-a-blog-with-pelican
  24. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 142 additions and 15 deletions.
    157 changes: 142 additions & 15 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -1,39 +1,45 @@
    # How to Pelican
    # How to Pelican on GitHub Pages

    ## Install on Ubuntu

    Installing Python tools
    ### Installing Pelican with Python tools

    ```
    sudo easy_install pip
    sudo pip install virtualenv
    sudo pip install virtualenvwrapper
    sudo pip install pelican markdown fabric virtualenv virtualenvwrapper
    ```

    `vi ~/.bashrc`

    vi ~/.bashrc
    ```sh
    # Virtualenvwrapper
    export WORKON_HOME=$HOME/.virtualenvs
    source /usr/local/bin/virtualenvwrapper.sh
    ```

    Load file `.bashrc`

    ```
    source ~/.bashrc
    ```

    Create virtualenv:

    ```
    mkvirtualenv blog
    workon blog
    # And to leave:
    deactivate
    ```

    Installing Pelican
    And to leave:

    ```
    sudo pip install pelican
    sudo pip install markdown
    deactivate
    ```

    Upgrading
    ### Upgrading Pelican

    ```
    pip install --upgrade pelican
    pip install --upgrade markdown
    pip install --upgrade pelican markdown
    ```

    ## Creating a blog on [GitHub Pages](https://help.github.com/categories/20/articles/)
    @@ -123,7 +129,7 @@ mkdir -p ./posts/2013/07
    vi welcome-all.md
    ```

    ```
    ```md
    Title: Welcome All
    Slug: welcome-all
    Date: 2013-07-22 19:19
    @@ -212,6 +218,127 @@ git checkout master

    Point your browser to you.github.com/blog , Awesome!!!

    ### Automation

    [Fabric](http://fabfile.org) is a tool, an awesome tool! to automate things, is most used for remote servers, but also works fine for local automation. Put `fabfile.py` in the root path of the blog in the `master` branch.

    Now you can use like this:

    `fab generate`: generates the html for developing (while writing)
    `fab serve`: Serves the blog in local
    `fab publish`: Does all the process of change, commit and publish gh-pages branch, needs to be in master branch while executing the command

    The `fabfile.py`:

    ```python
    import os
    import time

    from fabric.api import local, lcd, settings
    from fabric.utils import puts

    #If no local_settings.py then settings.py
    try:
    from local_settings import OUTPUT_PATH
    SETTINGS_FILE = "local_settings.py"
    except ImportError:
    from settings import OUTPUT_PATH
    SETTINGS_FILE = "settings.py"


    # Get directories
    ABS_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
    ABS_SETTINGS_FILE = os.path.join(ABS_ROOT_DIR, SETTINGS_FILE)
    ABS_OUTPUT_PATH = os.path.join(ABS_ROOT_DIR, OUTPUT_PATH)


    # Commands
    def generate(output=None):
    """Generates the pelican static site"""

    if not output:
    cmd = "pelican -s {0}".format(ABS_SETTINGS_FILE)
    else:
    cmd = "pelican -s {0} -o {1}".format(ABS_SETTINGS_FILE, output)

    local(cmd)


    def destroy(output=None):
    """Destroys the pelican static site"""

    if not output:
    cmd = "rm -r {0}".format(os.path.join(ABS_ROOT_DIR, OUTPUT_PATH))
    else:
    cmd = "rm -r {0}".format(output)

    with settings(warn_only=True):
    result = local(cmd)
    if result.failed:
    puts("Already deleted")


    def serve():
    """Serves the site in the development webserver"""
    print(ABS_OUTPUT_PATH)
    with lcd(ABS_OUTPUT_PATH):
    local("python -m SimpleHTTPServer")


    def git_change_branch(branch):
    """Changes from one branch to other in a git repo"""
    local("git checkout {0}".format(branch))


    def git_merge_branch(branch):
    """Merges a branch in other branch"""
    local("git merge {0}".format(branch))


    def git_push(remote, branch):
    """Pushes the git changes to git remote repo"""
    local("git push {0} {1}".format(remote, branch))


    def git_commit_all(msg):
    """Commits all the changes"""
    local("git add .")
    local("git commit -m \"{0}\"".format(msg))


    def publish():
    """Generates and publish the new site in github pages"""
    master_branch = "master"
    publish_branch = "gh-pages"
    remote = "origin"

    # Push original changes to master
    #push(remote, master_branch)

    # Change to gh-pages branch
    git_change_branch(publish_branch)

    # Merge master into gh-pages
    git_merge_branch(master_branch)

    # Generate the html
    generate(ABS_ROOT_DIR)

    # Commit changes
    now = time.strftime("%d %b %Y %H:%M:%S", time.localtime())
    git_commit_all("Publication {0}".format(now))

    # Push to gh-pages branch
    git_push(remote, publish_branch)

    # go to master
    git_change_branch(master_branch)
    ```

    ### Custom domain

    [Setting up a custom domain with Pages](https://help.github.com/articles/setting-up-a-custom-domain-with-pages)

    ## Resources

    * http://blog.xlarrakoetxea.org/posts/2012/10/creating-a-blog-with-pelican
  25. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 75 additions and 12 deletions.
    87 changes: 75 additions & 12 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -116,18 +116,6 @@ wget -O settings.py https://raw.github.com/getpelican/pelican/master/samples/pel
    cp settings.py local_settings.py
    ```

    To generate the static html we use:

    ```
    pelican -s ./local_settings.py
    ```

    This will take all the settings and apply, but if we want to override some settings we could do. For example to specify the ouput we use -o:

    ```
    pelican -s ./local_settings.py -o /tmp/myBlog
    ```

    ### Creating a post

    ```
    @@ -149,6 +137,81 @@ Summary: Short version for index and feeds
    This is the content of my blog post.
    ```

    ### Generate blog

    To generate the static html we use:

    ```
    pelican -s ./local_settings.py
    ```

    This will take all the settings and apply, but if we want to override some settings we could do. For example to specify the ouput we use `-o`:

    ```
    pelican -s ./local_settings.py -o /tmp/myBlog
    ```

    Then we have a new directory named `output`, our blog is there, so, to test it , insert there and run a simple server:

    ```
    cd ./output
    python -m SimpleHTTPServer 8000
    # For Python 3
    python -m http.server 8000
    ```

    Point your browser to `localhost:8000` and you will see the blog.

    ### Deploying the blog

    We start the process in the `master` branch:

    ```
    git add .
    git commit -m "First post: Welcome All"
    ```

    Push it to master (remember, this doesn't deploy the page, this is our source):

    ```
    git push origin master
    ```

    If we havent the gh-pages branch we create:

    ```
    git branch gh-pages
    ```

    Change to gh-pages and merge the master branch:

    ```
    git checkout gh-pages
    git merge master
    ```

    Now generate the HTML. But wait! github doesn't know that our webpage is in output dir, so we need to put our generated HTML in the root of the project, to do that we replace the settings outputdir in the command:

    ```
    pelican -s ./local_settings.py -o ./
    ```

    We are ready to deploy, commit all and push:

    ```
    git add .
    git commit -m "Publish Welcome All post"
    git push origin gh-pages
    ```

    We change again to our master branch and we are done :):

    ```
    git checkout master
    ```

    Point your browser to you.github.com/blog , Awesome!!!

    ## Resources

    * http://blog.xlarrakoetxea.org/posts/2012/10/creating-a-blog-with-pelican
  26. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -107,6 +107,27 @@ nosetests.xml
    .pydevproject
    ```

    ### Create a Pelican settings file

    Now we will create a pelican settings file called `local_settings.py`, this file will not be commited to the git repo, maybe has personal data. But we will upload a blank template named `settings.py`, so we create also this one, that has the same variables as `local_settings.py` but without the vars data. Edit the data you need (You can store the `local_settings.py` data in a private gist manually):

    ```
    wget -O settings.py https://raw.github.com/getpelican/pelican/master/samples/pelican.conf.py
    cp settings.py local_settings.py
    ```

    To generate the static html we use:

    ```
    pelican -s ./local_settings.py
    ```

    This will take all the settings and apply, but if we want to override some settings we could do. For example to specify the ouput we use -o:

    ```
    pelican -s ./local_settings.py -o /tmp/myBlog
    ```

    ### Creating a post

    ```
  27. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 30 additions and 1 deletion.
    31 changes: 30 additions & 1 deletion how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -29,6 +29,13 @@ sudo pip install pelican
    sudo pip install markdown
    ```

    Upgrading

    ```
    pip install --upgrade pelican
    pip install --upgrade markdown
    ```

    ## Creating a blog on [GitHub Pages](https://help.github.com/categories/20/articles/)

    ### Steps to publish a post
    @@ -100,7 +107,29 @@ nosetests.xml
    .pydevproject
    ```

    ### Creating a post

    ```
    mkdir -p ./posts/2013/07
    vi welcome-all.md
    ```

    ```
    Title: Welcome All
    Slug: welcome-all
    Date: 2013-07-22 19:19
    Category: Python
    Tags: pelican, publishing
    Author: Josef Jezek
    Summary: Short version for index and feeds
    # Welcome All
    This is the content of my blog post.
    ```

    ## Resources

    * http://blog.xlarrakoetxea.org/posts/2012/10/creating-a-blog-with-pelican
    * http://docs.getpelican.com/en/3.2/tips.html#publishing-to-github
    * http://docs.getpelican.com/en/latest/getting_started.html
    * http://docs.getpelican.com/en/latest/tips.html#publishing-to-github
  28. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 52 additions and 0 deletions.
    52 changes: 52 additions & 0 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -44,8 +44,60 @@ In parenthesis is the git branch we are working on:
    7. (`gh-pages`) push all the files (normally all the new HTML)
    8. (`master`) push all the files (normally only one post)

    ### Create git repository

    Clone git repository

    ```
    git clone [email protected]:user/blog.git
    cd ./blog
    ```

    Create in the root folder a file named `.gitignore`

    `vi .gitignore`

    ```
    #Custom
    local_settings.py
    output
    #Python
    *.py[cod]
    # C extensions
    *.so
    # Packages
    *.egg
    *.egg-info
    dist
    build
    eggs
    parts
    bin
    var
    sdist
    develop-eggs
    .installed.cfg
    lib
    lib64
    # Installer logs
    pip-log.txt
    # Unit test / coverage reports
    .coverage
    .tox
    nosetests.xml
    # Translations
    *.mo
    # Mr Developer
    .mr.developer.cfg
    .project
    .pydevproject
    ```

    ## Resources
  29. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -35,14 +35,14 @@ sudo pip install markdown

    In parenthesis is the git branch we are working on:

    * (`master`) Create the post in rst or md (rst and md are abbreviations for resTructuredText and markdown)
    * (`master`) Generate the HTML
    * (`master`) Check the post in a local server
    * (`master`) We could delete the output but dones't matter if we don't because git will ignore with our gitignore file
    * (`gh-pages`) Merge master branch
    * (`gh-pages`) Generate the HTML
    * (`gh-pages`) push all the files (normally all the new HTML)
    * (`master`) push all the files (normally only one post)
    1. (`master`) Create the post in rst or md (rst and md are abbreviations for resTructuredText and markdown)
    2. (`master`) Generate the HTML
    3. (`master`) Check the post in a local server
    4. (`master`) We could delete the output but dones't matter if we don't because git will ignore with our gitignore file
    5. (`gh-pages`) Merge master branch
    6. (`gh-pages`) Generate the HTML
    7. (`gh-pages`) push all the files (normally all the new HTML)
    8. (`master`) push all the files (normally only one post)

    ```
  30. @JosefJezek JosefJezek revised this gist Jul 22, 2013. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions how-to-pelican.md
    Original file line number Diff line number Diff line change
    @@ -31,18 +31,18 @@ sudo pip install markdown

    ## Creating a blog on [GitHub Pages](https://help.github.com/categories/20/articles/)

    Steps to publish a post
    ### Steps to publish a post

    In parenthesis is the git branch we are working on:

    * (`master`) Create the post in rst or md (rst and md are abbreviations for resTructuredText and markdown)
    * (master) Generate the HTML
    * (master) Check the post in a local server
    * (master) We could delete the output but dones't matter if we don't because git will ignore with our gitignore file
    * (gh-pages) Merge master branch
    * (gh-pages) Generate the HTML
    * (gh-pages) push all the files (normally all the new HTML)
    * (master) push all the files (normally only one post)
    * (`master`) Generate the HTML
    * (`master`) Check the post in a local server
    * (`master`) We could delete the output but dones't matter if we don't because git will ignore with our gitignore file
    * (`gh-pages`) Merge master branch
    * (`gh-pages`) Generate the HTML
    * (`gh-pages`) push all the files (normally all the new HTML)
    * (`master`) push all the files (normally only one post)

    ```