Example #1
0
def render_content(content):
    use_app = session.get('app')

    base_url = current_app.config.get('SITE_CANONICAL_URL')
    if not base_url:
        base_url = current_app.config.get('SITE_URL')

    if base_url:
        link = '%s%s' % (base_url.rstrip('/'), request.path)
    else:
        link = request.base_url

    extra_head = ['<meta property="og:url" content="%s">' % link]
    twitter = current_app.config.get('SITE_TWITTER')
    if twitter:
        extra_head.append('<meta name="twitter:site" content="@%s" />' %
                          twitter)

    extra_head.append('<link rel="canonical" href="%s">' % link)

    if base_url:
        schema = ('<script type="application/ld+json">'
                  '{"@context":"http://schema.org","@type":"WebSite",'
                  '"name":"%s","url":"%s"}'
                  '</script>') % (current_app.config.get('SITE_NAME'),
                                  base_url)
        extra_head.append(schema)

    if not is_robot() and use_app != 'no':
        token = gen_salt(16)
        session['token'] = token
        script = '<script>location.href="/app?token=%s"</script>' % token
        extra_head.append(script)

    return content.replace(u'</head>', u''.join(extra_head) + u'</head>')
Example #2
0
def hook_for_render():
    use_app = session.get('app')

    if not is_robot() and use_app == 'yes':
        return render_template('front/app.html')

    key = 'front:page:%s' % request.path
    content = cache.get(key)
    if content:
        return render_content(content)
Example #3
0
def hook_for_render():
    use_app = session.get('app')

    if not is_robot() and use_app == 'yes':
        return render_template('front/app.html')

    key = 'front:page:%s' % request.path
    content = cache.get(key)
    if content:
        return render_content(content)
Example #4
0
def run_app():
    if is_robot():
        abort(404)

    referrer = request.referrer
    store = session.pop('token', None)
    token = request.args.get('token')
    if referrer and store and token and store == token:
        session['app'] = 'yes'
        return redirect(referrer)

    if not referrer:
        return redirect('/')

    if not store:
        return 'Please Enable Cookie'

    session['app'] = 'no'
    return redirect(referrer)
Example #5
0
def run_app():
    if is_robot():
        abort(404)

    referrer = request.referrer
    store = session.pop('token', None)
    token = request.args.get('token')
    if referrer and store and token and store == token:
        session['app'] = 'yes'
        return redirect(referrer)

    if not referrer:
        return redirect('/')

    if not store:
        return 'Please Enable Cookie'

    session['app'] = 'no'
    return redirect(referrer)
Example #6
0
def render_content(content):
    use_app = session.get('app')

    base_url = current_app.config.get('SITE_CANONICAL_URL')
    if not base_url:
        base_url = current_app.config.get('SITE_URL')

    if base_url:
        link = '%s%s' % (base_url.rstrip('/'), request.path)
    else:
        link = request.base_url

    extra_head = ['<meta property="og:url" content="%s">' % link]
    twitter = current_app.config.get('SITE_TWITTER')
    if twitter:
        extra_head.append(
            '<meta name="twitter:site" content="@%s" />' % twitter
        )

    extra_head.append('<link rel="canonical" href="%s">' % link)

    if base_url:
        schema = (
            '<script type="application/ld+json">'
            '{"@context":"http://schema.org","@type":"WebSite",'
            '"name":"%s","url":"%s"}'
            '</script>'
        ) % (current_app.config.get('SITE_NAME'), base_url)
        extra_head.append(schema)

    if not is_robot() and use_app != 'no':
        token = gen_salt(16)
        session['token'] = token
        script = '<script>location.href="/app?token=%s"</script>' % token
        extra_head.append(script)

    return content.replace(u'</head>', u''.join(extra_head) + u'</head>')
Example #7
0
 def is_robot_view():
     if is_robot():
         return 'yes'
     return 'no'
Example #8
0
def view_zerqu_app(name):
    """A helper URL router for anything else."""
    if is_robot():
        abort(403)
    return render_template('front/app.html')
Example #9
0
def view_zerqu_app(name):
    """A helper URL router for anything else."""
    if is_robot():
        abort(403)
    return render_template('front/app.html')