Git Product home page Git Product logo

wok's Introduction

Wok

Build Status

Wok is a static website generator. It turns a pile of templates, content, and resources (like CSS and images) into a neat stack of plain HTML. Wok is distributed under the MIT license (see the LICENSE file for more details).

The idea is that you don't need a big server-side engine like PHP to generate every page every visit: you can generate them all ahead of time, and only regenerate things when something has changed. A good way this could be done would be with a post-commit hook on a git repository containing your content or layout.

I made wok because projects like Jekyll, Hyde, and Static were intriguing, but in the end didn't quite match what I wanted to do with my website. So I am writing my own. Funnily, the mythical website that inspired wok still hasn't been written.

Sample Sites

A bare bones site is included in the wok git repo, in the test directory. It is really just a playground for devs to test new features, and not a good learning tool.

The documentation site available in the doc directory should be a fairly complete example of a small site that is good to learn from.

For some real world examples check out these sites.

For some more documentation, checkout the doc site. To learn and share with other users, you can check out the wiki.

Installation

The recommended way to install wok is from the Python Package Index with this command.

sudo pip install wok

Alternatively, if you want to hack on wok or just need the latest code, you can run from git head, and if you want to you can install to your system directories with this command. Note that you will need to install dependencies by hand in this case.

sudo python2 setup.py install

###Dependencies All dependencies are available from pip. Although optional, you really should install either markdown or docutils, and if you install from pip, they will be installed for you. Pygments is used for syntax highlighting, and will also be installed from pip.

####Required

  • pyyaml
  • jinja2

####Optional

  • Markdown - for rendering markdown documents.
  • docutils - for rendering reStructuredText documents.
  • Pygments - for syntax highlighting.

Usage

You might be interested in the tutorial

To use wok, go to the directory where your site files are located, and run the command wok. No output will be given unless something goes wrong. If it returns without error, you should have a shiny new output folder containing some HTML, and your media that represents your shiny new site.

To aid in testing links on the site, wok includes a development server. You can run it with the command wok --server, which will generate the site as normal, and then run a webserver on port 8080. The comments on that particular file say:

Do NOT attempt to use this as anything resembling a production server. It is meant to be used as a development test server only.

This test server is slow, and likely insecure, but for local testing of the site during development, it is really convenient.

Wok pulls the pieces of your site from three places. For each of these places, you can modify the path wok looks for them in the configuration file.

Content

Pulled from a directory named content by default. Content is written in lightweight markup or in plain text, with an optional YAML header section. The directory structure of the file mean nothing to wok. It builds the structure of the site based on the titles and the category metadata.

Since wok uses lightweight mark up languages like Markdown and reStructuredText, it is easy to do nice formatting in the pages without using a GUI editor or a cumbersome language like HTML. Built in syntax highlighting and media copying make things even easier.

More info

Templates

Pulled from templates by default. Wok uses Jinja2 templates, with various variables exposed to build pages. This is a very flexible templating environment with control flow, filters, and other ways to slice and dice the data that wok gives you.

More info

Configuration

Settings can be changed in the file config in the current directory.

Possible configuration options (and their defaults) are

  • output_dir ('output') - Where the outputted files are put.

  • content_dir ('content') - Where to find the content.

  • templates_dir ('templates') - Where the templates are.

  • media_dir ('media') - Where the media files are copied from.

  • site_title ('Some Random wok Site') - Available to templates as site.title.

  • author (No default) - Fills site.author, and provides a default to page.author.

  • url_pattern (/{category}/{slug}.html) - The pattern used to name and place the output files. The default produces URLs like /category/subcategory/foo.html. To get "wordpress style" urls, you could use /{category}/{slug}/index.html.

    Available variables:

    • {category} - The category of the site, slash seperated.
    • {slug} - The slug of the page.
    • {page} - The current page.
    • {ext} - The extension that the page should used.
    • {date}, {datetime}, and {time} - The date/time from the metadata of the page
  • url_include_index (Yes) - If true, keep index.* in urls.

More info: config, urls.

wok's People

Contributors

198d avatar abbgrade avatar catherinedevlin avatar chrplace avatar cvan avatar dskecse avatar edunham avatar garyvdm avatar gchriz avatar hpvb avatar matt-garman avatar moreati avatar mostawesomedude avatar mythmon avatar ngokevin avatar oampo avatar philipbjorge avatar remram44 avatar stachern avatar uberj avatar vaygr avatar willkg avatar zopieux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wok's Issues

Rob's orphan page fix.

There is a problem that causes sites not to render if they included orphaned pages. @robatron fixed this, but I reverted the change in the pagination sprint. Figure out how to make the two things play together.

Get rid of Page.meta

It was convenient for reading in the header data, but now it complicates the external interface. Everything should be a property of Page.

How can it still support arbitrary metadata being passed if this happens?

Tests. We need them.

Today's... fun... with regression, and errors and github/git being wierd for me has inspired me that tests are needed.

More url pattern variables

Possible variables:

  • date stuff (year, month, day, day of week)
  • author
  • arbitrary variables? (kind of crazy, but it might be cool)

Post previews

Many time it would be convenient to have a "preview" or partial version of a page that is user controlled.

I propose that these two versions both work, and be equivalent:

Option 1 - Excplicit

title: Foo
preview: This is the preview of Foo.

---
This is the preview of Foo.

This is not the preview of Foo.

Option 2 - Implicit

title: Foo

---
This is the preview of Foo.

---

This is not the preview of Foo.

In both cases the content of Foo would be

This is the preview of Foo.
This is not the preview of Foo.

Simple tagging system

It would be super-fly to have a simple content tagging system that would allow us to:

  • Tag content with a comma-separated list (e.g., tag: foo, bar, herp, derp)
  • Access tag list in the templates with tags
  • Access tagged pages in the templates with tags['foo'].pages[0]

Make page.{date,time,datetime} be exactly that.

Both in the template interface, and the yaml header, date should be the date only (no time), time should be the time only (no date) and datetime should be the datetime.

Be smart about when multiple are specified, combining them. Page.date and Page.time should probably call out methods of Page.datetime to extract the relavent bits.

Python 3 doesn't like the version (in __init__.py)

For some reason python 3 doesn't like unicode string notation.

Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    from wok import version
  File "/home/uberj/wok/wok/__init__.py", line 1
    version = u'0.8.0'
                     ^
SyntaxError: invalid syntax

uberj@francium ~/wok (> ^ ^)> python --version
Python 3.2.2


Support page specific media

Things like post specific images. Will live in the content directory, along side the content, but will be treated similar to media in the media directory.

Pagination issue

Further to our IRC chat yesterday - I can confirm the pagination is still broken whenever only 2 pages are generated.

My previous example was 2 files and a limit of 1 - I'm now using 9 files and a limit of 5, and next/prev links don't work. The prev link works if I manually go to page 2, as you demonstrated yesterday.

This is using v0.8.1 stable from PIP.

Python Plugins

@robatron had the idea to have arbitrary code that could be ran to generate data for the site. This might be a good way to make wok extensible.

Make a better sample site.

The sample site should be the documentation site. It should show off the features of wok in an attractive way, both the generated pages, and the source code itself.

The current sample site is ugly, and doesn't make much sense to anyone except me.

"vary-on" feature

The vary-by feature would regenerate a page many times for every value of a particular variable. For example a page with the metadata vary-on: site.tags would be generated once for every tag on the site, and would have a variable that contained the name of each tag.

This would be good to make things like archive pages or to browse by tag.

{{ site.categories }} template tag

Have a {{ site.categories }} template tag that returns a list of categories and their associated pages, e.g., {{ site.categories['blog'] }} would return all pages with the category 'blog'.

Allow multiple authors.

The author metadata field should allow multiple authors to be specified, in the case of collaborative editing.

Pagination

Mainly for index pages.

How would this work? Right now I am thinking of this: Somehow a page will indicate it wants to be paginated, how many items there are per page, and someone give a collection of the items that make up a page. Then, during rendering, the current page number and other related info will be available as a template variable.

As the confusion above hints at, wok is not well suited to this.

Wok trying to read Vim swap files as content

Wok trys to read Vim swap files as content/templates. Results in an error similar to this:

Warning from metadata: You didn't specify a title in  .index.mkd.swp. Using the file name as a title.
Traceback (most recent call last):
  File "../wok/wok/wok.py", line 82, in <module>
    Wok()
  File "../wok/wok/wok.py", line 26, in __init__
    self.render_site()
  File "../wok/wok/wok.py", line 78, in render_site
    p.render()
  File "/home/rob/wok/wok/page.py", line 157, in render
    self.html = template.render(templ_vars)
  File "/usr/lib/pymodules/python2.7/jinja2/environment.py", line 891, in render
    return self.environment.handle_exception(exc_info, True)
  File "templates/default.html", line 7, in top-level template code
    {{ page.content }}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa3 in position 16: ordinal not in range(128)

Render content setting.

The render content setting should control whether or not a content file gets written to disk. It should not affect whether or not it gets rendered, templated, and passed to other bits of the code, like index pages and fragment-generated pages.

Wok is using Linux-specific system calls.

Tsk, tsk ;-)

C:\Users\ew630d\Documents\mystuff\wok>python -m wok.engine
Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\lib\site-packages\wok\engine.py", line 171, in <module>
    Engine()
  File "C:\Python27\lib\site-packages\wok\engine.py", line 51, in __init__
    self.load_pages()
  File "C:\Python27\lib\site-packages\wok\engine.py", line 115, in load_pages
    self.options, renderer))
  File "C:\Python27\lib\site-packages\wok\page.py", line 53, in __init__
    self.build_meta()
  File "C:\Python27\lib\site-packages\wok\page.py", line 90, in build_meta
    util.out.warn('Your slug should probably be all lower case, and '
  File "C:\Python27\lib\site-packages\wok\util.py", line 19, in warn
    self.pretty_print("Warning: {0}".format(message))
  File "C:\Python27\lib\site-packages\wok\util.py", line 31, in pretty_print
    _,w = [int(n) for n in os.popen('stty size', 'r').read().split()]
ValueError: need more than 0 values to unpack

Normally I'm not one to complain about Windows compatibility issues, but I'm trying to show that wok will work well in a Windows environment to grow the user base :)

Use YAML lists instead of CSV strings.

This makes parsing a bit nicer, and will prevent confusing people who already understand YAML.

Old style CSV tags (or other such listed values) should still work, but give a deprecation in 0.7.x.

RSS Feeds

It would be nice to generate RSS feeds from a wok site. To do this the template engine needs to stop assuming it is making html files all the time, and pages will need to provide a little more metadata. In particular, they need a unique id that won't change between runs.

Self serving test server

wok --server should generate the site then launch a webserver server on a port that is not 80 to test the site quickly and easily.

Math Typesetting

Integrating something like latex math would be really cool for making pretty equations. This should probably be made with some sort of extensible plug interface.

wok is too quiet.

It isn't obvious that wok succeeds when it runs. There should be some sort of output to signal that all went well.

What kind of things should that output say? List of files generated? Number of files?

Unicode auto escaping

Unicode in content files should be automatically escaped to html elements, such as acute "e"s.

Parentless category system

@MostAwesomeDude and I were talking about Wok's category system, and I have a suggestion: I don't think categories should have "parents", i.e., special content that has access to page.subpages. Instead, I suggest that every member of a category should have access to every other member of that category, i.e., pages.siblings.

This would solve a couple big problems:

  • Wouldn't force the user to set the slug as 'index', which is not intuitive
  • Wouldn't make the user keep track of which content is the parent of what category

'site.content.gather.post' hook not supplying `pages` variable to attached function

It appears that the site.content.gather.post hook is not providing its attached functions with the pages variable like it's supposed to according to the hook docs.

For example, in my function attached to the hook, I'm including a pages parameter, but when I try to run wok, I get the following error message:

rob@vinux ~/robmd.net $ ./wok --server
Traceback (most recent call last):
  File "/home/rob/wok/scripts/wok", line 4, in <module>
    Engine()
  File "/home/rob/wok/wok/engine.py", line 103, in __init__
    self.load_pages()
  File "/home/rob/wok/wok/engine.py", line 242, in load_pages
    for pages in self.run_hook('site.content.gather.post'):
  File "/home/rob/wok/wok/engine.py", line 167, in run_hook
    returns.append(hook(*args))
TypeError: process_title_images() takes exactly 1 argument (0 given)

Global page.author

It might be nice to be able to set a global author in the site config file that can be overwritten by the content-specific author field. That way, one would't always have to enter an author for every blog post, for example.

Getting date-related key error

Regardless of if I include the 'date', 'datetime', or 'time' field or not, I'm getting the following key error:

Traceback (most recent call last):
  File "../wok/wok/wok.py", line 82, in <module>
    Wok()
  File "../wok/wok/wok.py", line 24, in __init__
    self.load_pages()
  File "../wok/wok/wok.py", line 61, in load_pages
    self.all_pages.append(Page(os.path.join(root,f), self.options, renderer))
  File "/home/rob/wok/wok/page.py", line 80, in __init__
    self.build_meta()
  File "/home/rob/wok/wok/page.py", line 143, in build_meta
    self.meta['datetime'] = isodate.parse_datetime(self.meta[datetime_name])
KeyError: 'date'

wok fails if 'media' directory doesn't exist

Wok fails if the 'media' directory doesn't exist. If the media directory's only purpose is to contain media files, shouldn't it be optional?

Traceback (most recent call last):
  File "../wok/wok/wok.py", line 82, in <module>
    Wok()
  File "../wok/wok/wok.py", line 23, in __init__
    self.prepare_output()
  File "../wok/wok/wok.py", line 43, in prepare_output
    for name in os.listdir(self.options['media_dir']):
OSError: [Errno 2] No such file or directory: 'media'

The published context settings doesn't work right.

The publish metadata setting should make a file never show up in the variables of any template. As it is now a page with publish: false would still appear in a blog index page, but would not appear on disk, so would create a broken link.

Syntax highlighting

Use pygment to do code highlighting. Preferrably there would be a way native to each type of renderer to mark a chunk of text as code. Ideally you could also mark this code as a particular language.

site.date/site.time not set?

Tell me if I'm being stupid, but site.date and site.time don't seem to be set - I've looked through the code briefly and assumed it should be set here https://github.com/mythmon/wok/blob/master/wok/engine.py#L298

Would also be nice to not have microseconds appended to site.datetime unless there's a good reason for it? Maybe consider adding the timezone instead/as well. Let me know if you'd like me to raise those as separate feature requests :-) Edit: Just noticed you're using site.datetime.strftime() for this!

Wok doesn't handle under+overline headers in RST

Sample case was this:

=====================================
Something that should have been an h1
=====================================

Some text

The header (wrapped in ===) did not show up.

Options for generated content layout.

Add options for the structure of the generated sites.

  • Classic - /category/subcategory/slug.html (default, implemented now)
  • Clean - /category/subcategory/slug/index.html (possible now, but could be done cleaner)
  • Flat - /slug.html (For super simple sites)
  • Manual - Force all pages to define a url category.

I feel like I had another idea for an option, but I don't remember what it was now.

url field

Pages should have a url field. This can be defined in the YAML header to place the file in a non-default location. From templates it can be accessed to make links to pages.

It should be a relative path from the root of the output dir.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.