Exemplo n.º 1
0
def load(path=None, local=False, base_url=None):
    # Read default configuration file first.
    # So catsup can use the default value when user's conf is missing.
    # And user does't have to change conf file everytime he updates catsup.
    default_config = os.path.join(g.public_templates_path, 'config.json')
    config = parse(default_config)

    if path:
        user_config = parse(path)
        config = update_nested_dict(config, user_config)
        os.chdir(os.path.abspath(os.path.dirname(path)))
    g.theme = find_theme(config)
    g.source = config.config.source
    g.output = config.config.output
    g.permalink = config.permalink
    if base_url:
        g.base_url = add_slash(base_url)
    else:
        g.base_url = add_slash(config.site.url)
    config.site.url = g.base_url
    if local:
        import tempfile
        config.config.static_prefix = "/static/"
        config.config.output = tempfile.mkdtemp()

    g.static_prefix = urljoin(
        g.base_url,
        add_slash(config.config.static_prefix)
    )

    g.theme.vars = update_nested_dict(g.theme.vars, config.theme.vars)
    config.theme.vars = g.theme.vars
    config.path = path
    return config
Exemplo n.º 2
0
 def render_to(self, template, permalink, **kwargs):
     html = self.render(template, **kwargs)
     if not html:
         return
     permalink, output_name = urljoin(g.base_url, permalink), permalink
     kwargs.setdefault("permalink", permalink)
     self.rendered_permalinks.append(permalink)
     if output_name.endswith("/") or "." not in output_name:
         output_name = output_name.rstrip("/")
         output_name += '/index.html'
     output_path = os.path.join(g.output, output_name.lstrip("/"))
     mkdir(os.path.dirname(output_path))
     with open(output_path, "w") as f:
         f.write(html)
Exemplo n.º 3
0
 def render_to(self, template, permalink, **kwargs):
     permalink, output_name = urljoin(
         g.base_url,
         permalink
     ), permalink
     kwargs.setdefault("permalink", permalink)
     html = self.render(template, **kwargs)
     if html:
         self.rendered_permalinks.append(permalink)
         if output_name.endswith("/") or "." not in output_name:
             output_name = output_name.rstrip("/")
             output_name += '/index.html'
         output_path = os.path.join(g.output, output_name.lstrip("/"))
         mkdir(os.path.dirname(output_path))
         with open(output_path, "w") as f:
             f.write(html)