EzDevInfo.com

hyde

A Python Static Website Generator Overview awesome documentation for hyde - a python static website generator

How to install poole/hyde in Jekyll?

I am trying to build a blog using Jekyll ( http://jekyllbootstrap.com/usage/jekyll-quick-start.html) on github pages.

After publishing the site, a found a theme Hyde, that uses Poole (https://github.com/poole/poole/#readme).

I am finding it a bit tricky to install it over Jekyll. I hope someone can point me through.

Thanks!


Source: (StackOverflow)

Can I use something like Hyde from within Django?

I have a site with a few hundred pages where maybe 75% of pages are static content and the rest fit the typical "web application" model. My preference is Django, so I've mostly been looking at solutions based on that.

The content is very bespoke -- most pages share little beyond the basic site chrome, and are complex enough that it's simpler to write them in HTML rather than try to wrangle a rich text editor into giving the correct output. So the direction I'm currently going is to just define the content in templates -- I have a single view and use the incoming path as the template path. This keeps each page on the site as a page in the file system (easy to browse, easy to track in revision control), but lets each page share any number of common elements (headers, footers, navigation) and inject its own data into them as needed.

This gets bogged down in a lot of the details, though. For instance:

  • Sharing of page data with other pages. For example, the title defined by a page should show up in navigation menus on other pages, etc. I found this question about getting a block value from a template, but this seems really convoluted (and not scalable).
  • Related issue: if I define something as a block I can only use it once. I've seen the example of {% block title %} -- which typically goes in multiple places in a page -- several times in SO without a great solution.
  • Multiple/flexible inheritance. For a breadcrumb I might want to inherit from a page's ancestor, but for layout I'd probably want to inherit from something else (eg. a one-column vs two-column base template).

I think these specific issues are solvable on their own, mostly by using includes and custom template tags, but looking down that road I see hacks piled on top of hacks, which I'd like to avoid -- this needs to be a fairly simple and easily grokked system.

In the course of looking into these, I came across Hyde, which seems to address a lot of these issues. In particular, I really like that it has a sense of the site structure, and it gives pages some nice tools to navigate.

But I still have all the dynamic pieces, which really need to fit seamlessly. So anything I do for the content pages should really be available for any template that's part of a dynamic application. Also, one thing I really like about the "each page a template" approach is that I can alter the treatment of any particular page just by adding its path to urls.py and specifying a custom view.

Is there a good solution for this type of use case? More generally, is this just something that Django shouldn't be asked to do? It occurs to me that I'm sort of trying to use the file system as a CMS database here, which seems likely to lead to scaling problems, but Django seems to process and cache template content pretty well, and after looking at some existing CMS solutions (django-cms, feincms, fiber) I really don't like the idea of having one solution for static content and a totally different one for interactive content.

Edit

Here's what I got using custom tags to handle page metadata/configuration:

  1. A dictionary for page data is passed in at the top level (so that a tag can write into it and then code higher in the stack can read it back)
  2. A custom data tag allows pages to write data into this page data
  3. Other custom tags read and render structures (navigation, breadcrumbs, etc) from the data

The main piece is a tag that will read data (written as JSON) into the global dict:

class PageInfoNode(Node):

    def __init__(self, page_info):
        self.title = page_info['title']
        self.breadcrumb_title = page_info.get('breadcrumb_title', self.title)
        self.show_breadcrumb = page_info.get('show_breadcrumb', False)
        self.nav_title = page_info.get('nav_title', self.breadcrumb_title)
        self.side_nav = page_info.get('side_nav', None)

    def render(self, context):
        # 'page_info' must be set someplace higher in the context stack
        page_info = context['page_info']
        page_info['title'] = self.title
        page_info['nav_title'] = self.nav_title
        if self.show_breadcrumb:
            if 'breadcrumb' in page_info:
                page_info['breadcrumb'] = [self.breadcrumb_title] + page_info['breadcrumb']
            else:
                page_info['breadcrumb'] = [self.breadcrumb_title]
        if self.side_nav != None:
            page_info['side_nav'] = self.side_nav
        return ''

@register.tag
def pageinfo(parser, token):
    nodelist = parser.parse(('endpageinfo',))
    parser.delete_first_token()
    return PageInfoNode(json.loads(nodelist.render(Context())))

Each page sets its data like:

{% block data %}
{{ block.super }}
{% load my_page_tags %}
{% pageinfo %}
{
  "title": "My Page Title",
  "show_breadcrumb": true,
  "side_nav": ["/section1/page.html", "/section2/page.html"]
}
{% endpageinfo %}
{% endblock data %}

This works, but it seems really opaque and fragile:

  • The global dict needs to be added somehow -- right now I do it in the view, but I guess a custom context processor would be better
  • This needs to be in an inherited block so that it will actually render
  • Because we sometimes need the super's data (eg. for breadcrumbs) it needs to call {{ block.super }} but it needs to be in the right order to keep the super's data from overwriting the target page's data.

I just feel like I'm working against the way Django wants to operate, and I was hoping that there was some better way of handling this sort of thing that I was missing.


Source: (StackOverflow)

Advertisements

How to escape double brackets in Hyde markdown syntax

When using the Hyde static webpage generator I have Python code with double brackets

{% syntax %}
var[["some-string"]] = foo
{% endsyntax %}

This renders oddly because [["foo"]] is special Hyde markdown.

Normal escaping (e.g. through the use of HTML escape characters) fails because we're inside of a syntax block.

How does one escape characters within a Hyde syntax block?


Source: (StackOverflow)

Display all jinja object attributes

Is there a way to display the name/content/functions of all attributes of a given object in a jinja template. This would make it easier to debug a template that is not acting as expected.

I am building a website using the hyde framework and this would come in quite handy since I am still learning the intricacies of both jinja and hyde.

Originally, I had thought it would work to use the attr filter, but this seems to require a name value. I would like to to not have to specify the name in order to get all available attributes for the object.

Some google searching showed django syntax looks like the following, but I am not familiar with django so this may only apply to database items. Long story short, I would like a method that works kind of like this for any object named obj

{% for field, value in obj.get_fields %}
    {{ field }} : {{ value }} </br>
{% endfor %}

final solution:

@jayven was right, I could create my own jinja2 filter. Unfortunately, using the stable version of hyde (0.8.4), this is not a trivial act of having a filter in the pythonpath and setting a simple yaml value in the site.yaml file (There is a pull-request for that). That being said, I was able to figure it out! So the following is my final solution which ends up being very helpful for debugging any unkown attributes.

It's easy enough to create site-specific hyde extensions just create a local python package with the following directory tree

hyde_ext
    __init__.py
    custom_filters.py

Now create the extension:

from hyde.plugin import Plugin
from jinja2 import environmentfilter, Environment


debug_attr_fmt = '''name:  %s
type:  %r
value: %r'''

@environmentfilter
def debug_attr(env, value, verbose=False):
    '''
    A jinja2 filter that creates a <pre> block
    that lists all the attributes of a given object
    inlcuding the value of those attributes and type.

    This filter takes an optional variable "verbose",
    which prints underscore attributes if set to True.
    Verbose printing is off by default.
    '''

    begin = "<pre class='debug'>\n"
    end = "\n</pre>"

    result = ["{% filter escape %}"]
    for attr_name in dir(value):
        if not verbose and attr_name[0] == "_":
            continue
        a = getattr(value, attr_name)
        result.append(debug_attr_fmt % (attr_name, type(a), a))
    result.append("{% endfilter %} ")
    tmpl = Environment().from_string("\n\n".join(result))

    return begin + tmpl.render() + end

    #return "\n\n".join(result)

# list of custom-filters for jinja2
filters = {
        'debug_attr' : debug_attr
        }

class CustomFilterPlugin(Plugin):
    '''
    The curstom-filter plugin allows any
    filters added to the "filters" dictionary
    to be added to hyde
    '''
    def __init__(self, site):
        super(CustomFilterPlugin, self).__init__(site)

    def template_loaded(self,template):
        super(CustomFilterPlugin, self).template_loaded(template)
        self.template.env.filters.update(filters)

To let hyde know about the extension add hyde_ext.custom_filters.CustomFilterPlugin to the "plugins" list of the site.yaml file.

Lastly, test it out on a file, you can add this to some random page {{resource|debug_attr}} or the following to get even the underscore-attributes {{resource|debug_attr(verbose=True)}}

Of course, I should add, that it seems like this might become much easier in the future whenever hyde 1.0 is released. Especially since there is already a pull request waiting to implement a simpler solution. This was a great way to learn a little more about how to use jinja and hyde though!


Source: (StackOverflow)

Blog on Google App Engine [closed]

Hi i'm trying to host my blog on Google App Engine (Google quality & free ...) i looked everywhere for a solution.

I love jekyll project but since it's developed with ruby i can't host it on appengine.

I found hyde project ( which kind of python implemented version of jekyll) i'm thinking to use it on appengine, Are there anyone who's already using it on google appengine ?


Source: (StackOverflow)

How to generate new content with Hyde?

I'm starting to learn Hyde and I've cloned a few blogs written in Hyde from Github. I can successfully generate these sample blogs in my web browser and serve them locally; however, I can't seem to figure out how to actually generate new content. For example, how can I add a new file in HTML or markdown then serve the file to the site? I see no mention of how to do this in the docs. What am I missing? The directory structure of the sample blogs I'm working with looks like this:

---content
    ---about
    ---blog  
---deploy
    ---about
    ---blog
---layout
   ---base.j2
   ---listing.j2
   ---posts.j2
---info.yaml
---site.yaml

Can anyone explain how to add either HTML or markdown files and have them served?


Source: (StackOverflow)

TB fluid div alignment issue from hyde generated code

I have the following responsive blog archives layout, which is suffering from alignment issues but I'm not sure which element to target to remedy the issue.

In the linked jsFiddle example, adjusting the width does produce a responsive layout, but the listing of blog posts does not flow in proper alignment.

The below code from the hyde static site generator seems to put redundant <p> tags in, which I'm not sure if it needs to be remedied there or if some CSS adjustments will suffice.

{% extends "base.j2" %}
{% from "macros.j2" import render_excerpt with context  %}
{% block main %}
{% block page_title %}

<h1 class="title"></h1>

    <div class="page-header">
    <h1>{{ resource.meta.title }}</h1>
    </div>


{% endblock %}


  <div class="row-fluid">

    {% for res in resource.node.walk_resources_sorted_by_time() %}


    {% refer to res.url as post %}

        <div class="span4">
              <a rel='nofollow' href="{{ content_url(res.url) }}"><h2>{{ res.meta.title }}</h2></a>

    <a rel='nofollow' href="{{ content_url(res.url) }}" class="postpic">{{ post.image|markdown|typogrify }}</a>

{{ res.meta.excerpt|markdown|typogrify }}

              <p><a class="btn" rel='nofollow' href="{{ content_url(res.url) }}">View details &raquo;</a></p>
            </div><!--/span-->

    {% endfor %}

          </div><!--/row-->


{% endblock %}

Source: (StackOverflow)

Error hyde with python-3.x

I followed (https://github.com/hyde/hyde) and installed all requirements.txt using the command "hyde-s folder_name create-l starter "error occurs:

Traceback (most recent call last):
   File "C: \ Python33 \ Scripts \ hyde-script.py", line 9, in <module>
     load_entry_point ('== 0.8.4 hyde', 'console_scripts', 'hyde') ()
   File "C: \ Python33 \ lib \ site-packages \ hyde \ main.py", line 10, in main
     Engine (.) Run ()
   File "C: \ Python33 \ lib \ site-packages \ hyde \ engine.py", line 39, in run
     super (Engine, self). run (args)
   File "C: \ Python33 \ lib \ site-packages \ command \ application.py", line 252, in run
     self.parse args = (sys.argv [1:])
   File "C: \ Python33 \ lib \ site-packages \ command \ application.py", line 242, in parse
     self.__parser__.parse_args return () # pylint: disable-msg = E1101
AttributeError: 'Engine' object has no attribute '__parser__'

I saw the argparse that was installed has a "parse_args () (http://argparse.googlecode.com/svn/trunk/doc/parse_args.html)" tried unsuccessfully to adapt more.

Before I had to do a few adjustments example "from UserDict import IterableUserDict" as in "python 3x" has (http://docs.python.org/3.3/library/collections.html?highlight=userdict#collections.UserDict).


Source: (StackOverflow)

How to hide excerpt from single post view in Hyde?

I'm having some trouble with this Hyde project, my homepage and blog index page show correctly pulling from the individual blog post's excerpt and image marked sections, but when viewing the individual blog posts, the excerpt is also being shown, which I do not want.

Trying to customize the individual post template is an option I tried, but then failed to display those image and excerpt sections on the homepage and blog index.

Any solution which allows me to write the excerpt in the post content file as default, but hiding it from single post views would be ideal, but open to any suggestions.

Cheers,

Leon


Source: (StackOverflow)

Global include in restructured text

I'm using reStructuredText for my blog/website and I want to add a global include file. I have access to and am happy to change the settings file I'm using to generate the html output, I just can't figure out the syntax for either:

  1. adding a default include file to the parser
  2. defining directive/inline-roles, etc in python with docutils in python

I tried reading the source code and the documentation and just find it a bit hard to follow. I'm hoping that I just missed something super-obvious, but I'd like to do something like the following (the first part is just what is already there -- you can see the rest of the file in the jekyll-rst plugin source (links right to it)

import sys
from docutils.core import publish_parts
from optparse import OptionParser
from docutils.frontend import OptionParser as DocutilsOptionParser
from docutils.parsers.rst import Parser

# sets up a writer that is then called to parse rst pages repeatedly
def transform(writer=None, part=None):
    p = OptionParser(add_help_option=False)

    # Collect all the command line options
    docutils_parser = DocutilsOptionParser(components=(writer, Parser()))
    for group in docutils_parser.option_groups:
        p.add_option_group(group.title, None).add_options(group.option_list)

    p.add_option('--part', default=part)

    opts, args = p.parse_args()


# ... more settings, etc

# then I just tell the parser/writer to process specified file X.rst every time
# (or alternately a python file defining more roles...but nicer if in rst)

Is there a simple way to do this? It'd be great to define a file defaults.rst and have that load each time.

EDIT: Here are some examples of what I'd like to be able to globally include (custom directives would be nice too, but I'd probably write those in code)

.. role:: raw-html(raw)
   :format: html

.. |common-substitution| replace:: apples and orange

.. |another common substitution| replace:: etc

Source: (StackOverflow)

Hyde LessCSS plugin doesn't convert less files to css

I've been trying to get a hyde site going using the latest version available (0.8.4). I used the built in command to create a site hyde -s /path/to/dir create, and all worked fine. I then followed some examples I found to try and get LessCSS support by editing the site.yaml file:

plugins:
    - hyde.ext.plugins.meta.MetaPlugin
    - hyde.ext.plugins.auto_extend.AutoExtendPlugin
    - hyde.ext.plugins.sorter.SorterPlugin
    - hyde.ext.plugins.tagger.TaggerPlugin
    - hyde.ext.plugins.syntext.SyntextPlugin
    - hyde.ext.plugins.textlinks.TextlinksPlugin
    - hyde.ext.plugins.less.LessCSSPlugin

# ...

less:
    app: /path/to/lessc

I added a very basic less file to check that it works:

/* content/media/css/style.less */
@color: blue;
body { background-color: @color; }

And included it in my application:

<link rel="stylesheet" rel='nofollow' href="{{ media_url('css/style.css') }}">

When I generate the site, I see the the proper css in the command line output body{background-color:blue};, but the file deploy/media/css/style.css is just a copy of the less file. Documentation on this is not great - has anyone got it to work? thanks.


Source: (StackOverflow)

Writing translatable static web pages using Django

I am a bit confused on the best way to handle this problem:

My web site needs read-only static web pages (typically the About part of a web site) with 2 simple constraints:

  • they need to be translated
  • they need to have flexible layout: to incorporate base headers/footers, floating images and/or tables, and non-interactive elements (like a bootstrap carousel).

Several solutions that I have thought about:

  • I can of course directly write HTML files but the translation part will be awkward (a lot of <h1>, <ul>, <li> and <p> which are of no interest to the translator).
  • I can use Django flatpages with some markup languages but I lose a lot of flexibility (for instance template tags are not recognized)
  • Use generators like Hyde, but it seems quite overkill for my needs and internationalization seems a bit difficult

Does someone have other propositions that I can look into ?

Thanks !


Source: (StackOverflow)

Is Hyde (Python) a stand alone solution? [closed]

According to the Hyde website, Hyde is based on the Django template engine. I don't want to install Django and Hype. So, a yes/no question: Is it a stand alone solution?


Source: (StackOverflow)

Hyde static page site generator - issue with running hyde command from command line

I installed Hyde with pip. I can see hyde in /usr/local/share/python. But when I am running hyde from command line, I am getting "Bash - Command not found error".

I am on Mac OSX (ML) and python 2.7.3

Please help.


Source: (StackOverflow)

What makes static site generators like Jekyll and Hyde better than XML and XSLT?

The idea seems to be very similar by keeping actual content separate from the final output rendering so that changing the template or styling is trivial.


Source: (StackOverflow)