コード例 #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>')
コード例 #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)
コード例 #3
0
ファイル: front.py プロジェクト: VincentRong/zerqu
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)
コード例 #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)
コード例 #5
0
ファイル: front.py プロジェクト: VincentRong/zerqu
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)
コード例 #6
0
ファイル: front.py プロジェクト: VincentRong/zerqu
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>')
コード例 #7
0
ファイル: test_libs.py プロジェクト: marslabtron/zerqu
 def is_robot_view():
     if is_robot():
         return 'yes'
     return 'no'
コード例 #8
0
ファイル: front.py プロジェクト: 343829084/zerqu
def view_zerqu_app(name):
    """A helper URL router for anything else."""
    if is_robot():
        abort(403)
    return render_template('front/app.html')
コード例 #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')