def iframe(ctx, content): #: together with IframeWriter import re import os import logging from liquidluck.options import g from liquidluck.utils import get_relative_base writer = ctx.get("writer") base = get_relative_base(writer["filepath"]) regex = ur"\[\[iframe:(\S*?)\]\]" def repl(m): key = m.group(1) item = g.resource["iframe"].get(key) h = "" if item: height = item.get("height") if height: h = 'height="%s"' % height else: logging.warn("Iframe not found: %s" % key) path, name = os.path.split(key) src = "%s/%s/iframe-%s.html" % (base, path, name.lower()) return ( '<div class="ff-iframe">' '<iframe src="%s" allowtransparency="true" ' 'frameborder="0" scrolling="0" %s></iframe>' "</div>" ) % (src, h) return re.sub(regex, repl, content)
def iframe(ctx, content): #: together with IframeWriter import re import logging from liquidluck.options import g from liquidluck.utils import get_relative_base writer = ctx.get('writer') base = get_relative_base(writer['filepath']) regex = ur'\[\[iframe:(\S*?)\]\]' def repl(m): name = m.group(1) item = g.resource['iframe'].get(name) h = '' if item: height = item.get('height') if height: h = 'height="%s"' % height else: logging.warn('Iframe not found: %s' % name) src = '%s/iframe/%s.html' % (base, name.lower()) return ('<div class="ff-iframe">' '<iframe src="%s" allowtransparency="true" ' 'frameborder="0" scrolling="0" %s></iframe>' '</div>' ) % (src, h) return re.sub(regex, repl, content)
def create_url(ctx, path): hsh = get_hsh(path)[:5] prefix = settings.static_prefix.rstrip("/") if settings.use_relative_url and not prefix.startswith("http"): base = get_relative_base(ctx.get("writer")["filepath"]) prefix = "%s/%s" % (base, prefix.lstrip("/")) url = "%s/%s?v=%s" % (prefix, path, hsh) return url
def create_url(ctx, path): hsh = get_hsh(path)[:5] prefix = settings.config.get('static_prefix', '/static/').rstrip('/') use_relative_url = settings.config.get('relative_url', False) if use_relative_url and not prefix.startswith('http'): base = get_relative_base(ctx.get('writer')['filepath']) prefix = '%s/%s' % (base, prefix.lstrip('/')) url = '%s/%s?v=%s' % (prefix, path, hsh) return url
def content_url(ctx, base, *args): writer = ctx.get('writer') def fix_index(url): if url.endswith('/index.html'): return url[:-10] return url args = list(args) base = to_unicode(base) use_relative_url = settings.config.get('relative_url', False) if base.startswith('http://') or base.startswith('https://'): prefix = '%s/' % base.rstrip('/') elif use_relative_url and writer: prefix = '%s/' % get_relative_base(writer['filepath']) args.insert(0, base) else: prefix = '/' args.insert(0, base) args = map(lambda o: to_unicode(o).strip('/'), args) url = '/'.join(args).replace('//', '/').replace(' ', '-') url = prefix + url.lstrip('/') url = to_unicode(fix_index(url.lower())) if url.endswith('/'): return url permalink = settings.config['permalink'] if permalink.endswith('.html'): if url.endswith('.html'): return url if url.endswith('.xml'): return url return '%s.html' % url if permalink.endswith('/'): if url.endswith('.html'): url = fix_index(url) url = url.rstrip('.html') if url.endswith('.xml'): url = url.rstrip('.xml') return '%s/' % url if url.endswith('.html'): url = fix_index(url) return url.rstrip('.html') if url.endswith('.xml'): return url.rstrip('.xml') return url
def content_url(ctx, base, *args): writer = ctx.get("writer") def fix_index(url): if url.endswith("/index.html"): return url[:-10] return url args = list(args) base = to_unicode(base) if base.startswith("http://") or base.startswith("https://"): prefix = "%s/" % base.rstrip("/") elif settings.use_relative_url and writer: prefix = "%s/" % get_relative_base(writer["filepath"]) args.insert(0, base) else: prefix = "/" args.insert(0, base) args = map(lambda o: to_unicode(o).strip("/"), args) url = "/".join(args).replace("//", "/").replace(" ", "-") url = prefix + url.lstrip("/") url = to_unicode(fix_index(url.lower())) if url.endswith("/"): return url if settings.permalink.endswith(".html"): if url.endswith(".html"): return url if url.endswith(".xml"): return url return "%s.html" % url if settings.permalink.endswith("/"): if url.endswith(".html"): url = fix_index(url) url = url.rstrip(".html") if url.endswith(".xml"): url = url.rstrip(".xml") return "%s/" % url if url.endswith(".html"): url = fix_index(url) return url.rstrip(".html") if url.endswith(".xml"): return url.rstrip(".xml") return url
def permalink(ctx, post, prepend_site=False): writer = ctx.get('writer') slug = get_post_slug(post, settings.config["permalink"]) if prepend_site: url = '%s/%s' % (settings.site['url'].rstrip('/'), slug) elif settings.config['relative_url'] and writer: base = get_relative_base(writer['filepath']) url = '%s/%s' % (base, slug) else: url = '/%s' % slug if url.endswith('/index.html'): return url[:-10] return url
def src_js(ctx, files): import os from liquidluck.options import g from liquidluck.utils import get_relative_base writer = ctx.get("writer") base = get_relative_base(writer["filepath"]) src = os.path.abspath(os.path.join(g.source_directory, "src")) dct = {} for f in files: f = os.path.abspath(f) name = f[len(src) + 1 :] if src in f and name.endswith(".js") and "/" not in name: dct[name[:-3]] = "%s/src/%s" % (base, name) return dct
def src_js(ctx, files): import os from liquidluck.options import g from liquidluck.utils import get_relative_base writer = ctx.get('writer') base = get_relative_base(writer['filepath']) src = os.path.abspath(os.path.join(g.source_directory, 'src')) dct = {} for f in files: f = os.path.abspath(f) name = f[len(src) + 1:] if src in f and name.endswith('.js') and '/' not in name: dct[name[:-3]] = '%s/src/%s' % (base, name) return dct