浏览代码

Prepend / in Relative URLs in the whole HTML document

version-14
Anand Doshi 11 年前
父节点
当前提交
dc13555b23
共有 15 个文件被更改,包括 30 次插入40 次删除
  1. +1
    -2
      webnotes/__init__.py
  2. +4
    -4
      webnotes/templates/base.html
  3. +4
    -14
      webnotes/templates/generators/web_page.html
  4. +1
    -1
      webnotes/templates/generators/web_page.py
  5. +1
    -1
      webnotes/templates/includes/blogger.html
  6. +1
    -1
      webnotes/templates/includes/breadcrumbs.html
  7. +1
    -1
      webnotes/templates/includes/footer.html
  8. +2
    -2
      webnotes/templates/includes/inline_post.html
  9. +3
    -3
      webnotes/templates/includes/navbar.html
  10. +1
    -1
      webnotes/templates/includes/post_editor.html
  11. +1
    -1
      webnotes/templates/includes/slideshow.html
  12. +2
    -2
      webnotes/templates/pages/app.html
  13. +0
    -5
      webnotes/utils/__init__.py
  14. +1
    -0
      webnotes/website/css/website.css
  15. +7
    -2
      webnotes/webutils.py

+ 1
- 2
webnotes/__init__.py 查看文件

@@ -570,7 +570,7 @@ def get_jenv():
return jenv
def set_filters(jenv):
from webnotes.utils import global_date_format, scrub_relative_url
from webnotes.utils import global_date_format
from webnotes.webutils import get_hex_shade
from markdown2 import markdown
from json import dumps
@@ -578,7 +578,6 @@ def set_filters(jenv):
jenv.filters["global_date_format"] = global_date_format
jenv.filters["markdown"] = markdown
jenv.filters["json"] = dumps
jenv.filters["scrub_relative_url"] = scrub_relative_url
jenv.filters["get_hex_shade"] = get_hex_shade
# load jenv_filters from hooks.txt


+ 4
- 4
webnotes/templates/base.html 查看文件

@@ -7,8 +7,8 @@
<meta name="generator" content="wnframework">
<script type="text/javascript" src="/assets/webnotes/js/lib/jquery/jquery.min.js"></script>
<link rel="shortcut icon" href="{{ favicon | scrub_relative_url }}" type="image/x-icon">
<link rel="icon" href="{{ favicon | scrub_relative_url }}" type="image/x-icon">
<link rel="shortcut icon" href="{{ favicon }}" type="image/x-icon">
<link rel="icon" href="{{ favicon }}" type="image/x-icon">
{% block head -%}
{%- if meta_description is defined -%}
@@ -16,11 +16,11 @@
{%- endif -%}
{%- for link in web_include_js -%}
<script type="text/javascript" src="{{ link | scrub_relative_url }}"></script>
<script type="text/javascript" src="{{ link }}"></script>
{%- endfor -%}
{%- for link in web_include_css -%}
<link type="text/css" rel="stylesheet" href="{{ link | scrub_relative_url }}">
<link type="text/css" rel="stylesheet" href="{{ link }}">
{%- endfor -%}
{% block script -%}


+ 4
- 14
webnotes/templates/generators/web_page.html 查看文件

@@ -2,27 +2,18 @@

{% block header %}{% if show_title %}<h2>{{ title }}</h2>{% endif %}{% endblock %}

{% block breadcrumbs %}{% include "templates/includes/breadcrumbs.html" %}{% endblock %}

{% block content %}
<div class="webpage-content">
{# title, breadcrumbs, table of contents #}
{% block pre_content -%}
{% if show_breadcrumbs and breadcrumbs -%}
<ul class="breadcrumb">
{% for b in breadcrumbs -%}
<li><a href="{{ b.page_name }}">{{ b.title }}</a></li>
{%- endfor %}
<li class="active">{{ title }}</li>
</ul>
{%- endif %}
{%- endblock %}

{% include "templates/includes/slideshow.html" %}
<div class="web-page-content" id="{{ name }}">
{{ main_section or "" }}
</div>
{# toc, parent, child, next sibling #}
{% block post_content -%}
{% if show_toc and toc_list -%}
<div class="well">
<h4>Contents</h4>
@@ -53,7 +44,6 @@
<h3>Discuss</h3>
{% include 'templates/includes/comments.html' %}
{%- endif %}
{%- endblock %}
</div>
<script>
$(function() {
@@ -71,4 +61,4 @@ $(function() {

{% block style %}{{ style }}{% endblock %}

{% block script %}{{ script }}{% endblock %}
{% block script %}{{ script }}{% endblock %}

+ 1
- 1
webnotes/templates/generators/web_page.py 查看文件

@@ -16,7 +16,7 @@ def get_context(context):
web_page.doc.meta_description = web_page.doc.description
web_page.doc.breadcrumbs = get_breadcrumbs(web_page)
# web_page.doc.breadcrumbs = get_breadcrumbs(web_page)
web_page.doc.toc_list = get_toc_list(web_page)
# parent, child, next sibling links


+ 1
- 1
webnotes/templates/includes/blogger.html 查看文件

@@ -1,7 +1,7 @@
<div class="row">
<div class="col-md-2">
<div class="avatar avatar-large">
<img itemprop="thumbnailUrl" src="{{ blogger_info.avatar | scrub_relative_url }}" />
<img itemprop="thumbnailUrl" src="{{ blogger_info.avatar }}" />
</div>
</div>
<div class="col-md-10">


+ 1
- 1
webnotes/templates/includes/breadcrumbs.html 查看文件

@@ -1,7 +1,7 @@
{% if parents -%}
<ul class="breadcrumb">
{% for parent in parents %}
<li><a href="/{{ parent.name|lower }}">{{ parent.page_title }}</a></li>
<li><a href="/{{ parent.name|lower }}">{{ parent.page_title or parent.title }}</a></li>
{% endfor %}
<li class="active">{{ title }}</li>
</ul>

+ 1
- 1
webnotes/templates/includes/footer.html 查看文件

@@ -5,7 +5,7 @@
<div class="col-xs-9 web-footer-menu">
<ul class="list-inline">
{% for item in footer_items %}
<li><a href="{{ item.url | scrub_relative_url }}" {{ item.target }}
<li><a href="{{ item.url }}" {{ item.target }}
data-label="{{ item.label }}">{{ item.label }}</a></li>
{% endfor %}
</ul>


+ 2
- 2
webnotes/templates/includes/inline_post.html 查看文件

@@ -6,7 +6,7 @@
data-group="{{ post.website_group }}"
itemscope itemtype="http://schema.org/Article">
<a class="pull-left media-link" href="{{ post_url }}">
<img class="media-object post-avatar" src="{{ post.user_image|scrub_relative_url }}">
<img class="media-object post-avatar" src="{{ post.user_image }}">
</a>
<div class="media-body">
{%- if not post.parent_post -%}
@@ -50,7 +50,7 @@
{%- endif -%}
{{ post.content|markdown }}
{%- if post.picture_url -%}
<img src="{{ post.picture_url|scrub_relative_url }}" class="img-responsive post-picture" />
<img src="{{ post.picture_url }}" class="img-responsive post-picture" />
{%- endif -%}
</div>
</div>

+ 3
- 3
webnotes/templates/includes/navbar.html 查看文件

@@ -19,7 +19,7 @@
{%- for page in top_bar_items -%}
{% if not page.parent_label -%}
<li data-label="{{ page.label }}" {% if page.child_items %} class="dropdown"{% endif %}>
<a href="{{ page.url | scrub_relative_url }}" {% if page.child_items %} class="dropdown-toggle" onclick="return false;" data-toggle="dropdown"{% endif %} {{ page.target or ''}}>
<a href="{{ page.url or '' }}" {% if page.child_items %} class="dropdown-toggle" onclick="return false;" data-toggle="dropdown"{% endif %} {{ page.target or ''}}>
{{ page.label }}
{%- if page.child_items -%}
<span class="caret"></span>
@@ -28,7 +28,7 @@
{%- for child in page.child_items -%}
<li data-label="{{ child.label }}">
<a {% if child.indent %} style="padding-left: {{((child.indent|int)+1)*15 }}px"{% endif %}
href="{{ child.url | scrub_relative_url }}" {{ child.target or '' }}>{{ child.label }}</a>
href="{{ child.url }}" {{ child.target or '' }}>{{ child.label }}</a>
</li>
{%- endfor -%}
</ul>
@@ -53,7 +53,7 @@
{% if child.class %} class="{{ child.class }}" {% endif %}>

{%- if child.url -%}
<a href="{{ child.url | scrub_relative_url }}" {{ child.target or '' }}>
<a href="{{ child.url }}" {{ child.target or '' }}>
{%- if child.icon -%}
<i class="icon-fixed-width {{ child.icon }}"></i>
{%- endif -%}


+ 1
- 1
webnotes/templates/includes/post_editor.html 查看文件

@@ -51,7 +51,7 @@
<div class="text-muted small">tab + enter to post / <a target="_blank" class="text-muted"
href="/markdown-cheatsheet" tabindex="-1">markdown formatting</a></div>
<div class="post-picture hide" style="margin: 10px 0px;">
<img src="{{ post.picture_url|scrub_relative_url if post else ''}}" class="img-responsive" />
<img src="{{ post.picture_url if post else ''}}" class="img-responsive" />
</div>
<div class="clearfix">
<button class="btn btn-default btn-post-add pull-right"><i class="icon-plus"></i> Add Post</button>


+ 1
- 1
webnotes/templates/includes/slideshow.html 查看文件

@@ -15,7 +15,7 @@
<div class="carousel-inner">
{% for slide in slides %}
<div class="{% if slide.idx==1 %}active {% endif %}item">
<img src="{{ slide.image | scrub_relative_url }}" class="slide-image" />
<img src="{{ slide.image }}" class="slide-image" />
{% if slide.heading or slide.description %}
<div class="carousel-caption">
{% if slide.heading %}<h4>{{ slide.heading }}</h4>{% endif %}


+ 2
- 2
webnotes/templates/pages/app.html 查看文件

@@ -14,7 +14,7 @@
</div>
<footer></footer>
{% for include in include_css -%}
<link type="text/css" rel="stylesheet" href="{{ include | scrub_relative_url }}">
<link type="text/css" rel="stylesheet" href="{{ include }}">
{%- endfor -%}
<script type="text/javascript" src="/assets/webnotes/js/lib/jquery/jquery.min.js"></script>
<script type="text/javascript">
@@ -24,6 +24,6 @@
</script>

{% for include in include_js -%}
<script type="text/javascript" src="{{ include | scrub_relative_url }}"></script>
<script type="text/javascript" src="{{ include }}"></script>
{%- endfor -%}
</body>

+ 0
- 5
webnotes/utils/__init__.py 查看文件

@@ -842,11 +842,6 @@ def get_url_to_form(doctype, name, base_url=None, label=None):
return """<a href="%(base_url)s/app.html#!Form/%(doctype)s/%(name)s">%(label)s</a>""" % locals()
def scrub_relative_url(url):
if not url or url.startswith("http"):
return url
return "/" + url

def encode_dict(d, encoding="utf-8"):
for key in d:
if isinstance(d[key], basestring) and isinstance(d[key], unicode):


+ 1
- 0
webnotes/website/css/website.css 查看文件

@@ -220,6 +220,7 @@ fieldset {

.page-container {
margin-top: 15px;
padding-bottom: 30px;
}

.page-header h1,


+ 7
- 2
webnotes/webutils.py 查看文件

@@ -3,7 +3,7 @@

from __future__ import unicode_literals
import webnotes
import json, os, time
import json, os, time, re
from webnotes import _
import webnotes.utils
from webnotes.utils import get_request_site_address, encode, cint
@@ -76,6 +76,7 @@ def build_page(page_name):
context = get_context(page_name)
html = webnotes.get_template(context.base_template_path).render(context)
html = scrub_relative_urls(html)
if can_cache(context.no_cache):
webnotes.cache().set_value("page:" + page_name, html)
@@ -430,6 +431,10 @@ def render_blocks(context):
# render each block individually
for block, render in template.blocks.items():
out[block] = concat(render(context))
out[block] = scrub_relative_urls(concat(render(context)))

return out

def scrub_relative_urls(html):
"""prepend a slash before a relative url"""
return re.sub("""(src|href)[^\w'"]*['"](?!http|ftp|/|#)([^'" >]+)['"]""", '\g<1> = "/\g<2>"', html)

正在加载...
取消
保存