Browse Source

Prepend / in Relative URLs in the whole HTML document

version-14
Anand Doshi 11 years ago
parent
commit
dc13555b23
15 changed files with 30 additions and 40 deletions
  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 View File

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


+ 4
- 4
webnotes/templates/base.html View File

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


+ 4
- 14
webnotes/templates/generators/web_page.html View File

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


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


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

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


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


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

+ 1
- 1
webnotes/templates/generators/web_page.py View File

@@ -16,7 +16,7 @@ def get_context(context):
web_page.doc.meta_description = web_page.doc.description 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) web_page.doc.toc_list = get_toc_list(web_page)
# parent, child, next sibling links # parent, child, next sibling links


+ 1
- 1
webnotes/templates/includes/blogger.html View File

@@ -1,7 +1,7 @@
<div class="row"> <div class="row">
<div class="col-md-2"> <div class="col-md-2">
<div class="avatar avatar-large"> <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> </div>
<div class="col-md-10"> <div class="col-md-10">


+ 1
- 1
webnotes/templates/includes/breadcrumbs.html View File

@@ -1,7 +1,7 @@
{% if parents -%} {% if parents -%}
<ul class="breadcrumb"> <ul class="breadcrumb">
{% for parent in parents %} {% 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 %} {% endfor %}
<li class="active">{{ title }}</li> <li class="active">{{ title }}</li>
</ul> </ul>

+ 1
- 1
webnotes/templates/includes/footer.html View File

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


+ 2
- 2
webnotes/templates/includes/inline_post.html View File

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

+ 3
- 3
webnotes/templates/includes/navbar.html View File

@@ -19,7 +19,7 @@
{%- for page in top_bar_items -%} {%- for page in top_bar_items -%}
{% if not page.parent_label -%} {% if not page.parent_label -%}
<li data-label="{{ page.label }}" {% if page.child_items %} class="dropdown"{% endif %}> <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 }} {{ page.label }}
{%- if page.child_items -%} {%- if page.child_items -%}
<span class="caret"></span> <span class="caret"></span>
@@ -28,7 +28,7 @@
{%- for child in page.child_items -%} {%- for child in page.child_items -%}
<li data-label="{{ child.label }}"> <li data-label="{{ child.label }}">
<a {% if child.indent %} style="padding-left: {{((child.indent|int)+1)*15 }}px"{% endif %} <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> </li>
{%- endfor -%} {%- endfor -%}
</ul> </ul>
@@ -53,7 +53,7 @@
{% if child.class %} class="{{ child.class }}" {% endif %}> {% if child.class %} class="{{ child.class }}" {% endif %}>


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


+ 1
- 1
webnotes/templates/includes/post_editor.html View File

@@ -51,7 +51,7 @@
<div class="text-muted small">tab + enter to post / <a target="_blank" class="text-muted" <div class="text-muted small">tab + enter to post / <a target="_blank" class="text-muted"
href="/markdown-cheatsheet" tabindex="-1">markdown formatting</a></div> href="/markdown-cheatsheet" tabindex="-1">markdown formatting</a></div>
<div class="post-picture hide" style="margin: 10px 0px;"> <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>
<div class="clearfix"> <div class="clearfix">
<button class="btn btn-default btn-post-add pull-right"><i class="icon-plus"></i> Add Post</button> <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 View File

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


+ 2
- 2
webnotes/templates/pages/app.html View File

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


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

+ 0
- 5
webnotes/utils/__init__.py View File

@@ -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() 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"): def encode_dict(d, encoding="utf-8"):
for key in d: for key in d:
if isinstance(d[key], basestring) and isinstance(d[key], unicode): if isinstance(d[key], basestring) and isinstance(d[key], unicode):


+ 1
- 0
webnotes/website/css/website.css View File

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


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


.page-header h1, .page-header h1,


+ 7
- 2
webnotes/webutils.py View File

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


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


return out 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)

Loading…
Cancel
Save