PeterSmith.Org

Using fabric

    It's all well and good to use make (or even gmake) to automate the creation of pelican stuff–e.g., uploading to the server, rebuilding the content, etc). But, on Windoz systems 'make' is not always available.

    As a result I'm looking at fabric. Out of the box, Pelican will install fabric scripts to automate much of the posting/updating process. However, it has taken me a little while to find an examples of using fabric to create new posts (or, more accurately, to easy the creation of new posts). I modified the code a little to use markdown rather than rst, and I added some code to launch vim to edit the post.

    
      import sys
      from datetime import datetime
    
      TEMPLATE = """
      Title: {title}
      Date: {year}-{month}-{day} {hour}:{minute:02d}
      Category: Blogging
      Author: Peter
    
    
      """
    
      def newpost(title):
          today = datetime.today()
          slug = title.lower().strip().replace(' ', '-')
          f_create = "content/{}-{:0>2}-{:0>2}-{}.md".format(
          today.year, today.month, today.day, slug)
          t = TEMPLATE.strip().format(title=title,
                      year=today.year,
                      month=today.month,
                      day=today.day,
                      hour=today.hour,
                      minute=today.minute,
                      slug=slug)
          with open(f_create, 'w') as w:
          w.write(t)
          print("File created -> " + f_create)
          local("vim  '{}'".format(f_create))

    Anyway, it is working now so I'll probably propagate this fabfile to the other blogs I'm using.


    Webmentions
    If you webmention this page, please let me know the URL of your page.

    BTW: Your webmention won't show up until I next "build" my site.

    Word count: 200 (about 1 minutes)

    Published:

    Updated: 26 Jan '15 12:19

    Author: Peter Smith

    Permalink: https://petersmith.org/blog/2015/01/26/using-fabric/

    Section: blog

    Kind: page

    Bundle type: leaf

    Source: blog/2015/01/26/using-fabric/index.org