Finally a nice solution for mapping relative urls

source
Brandon Mathis 2011-07-21 23:50:32 -04:00
parent 44e1351fc7
commit 39d56bc988
13 changed files with 38 additions and 29 deletions

View File

@ -1,5 +1,5 @@
{% capture category %}{{ post.categories | size }}{% endcapture %}
<h1><a href="{{ site.root }}{{ post.url }}">{{post.title}}</a></h1>
<h1><a href="{{ root_url }}{{ post.url }}">{{post.title}}</a></h1>
<time datetime="{{ post.date | datetime }}" pubdate>{{ post.date | date: "<span class='month'>%b</span> <span class='day'>%d</span> <span class='year'>%Y</span>"}}</time>
{% if category != '0' %}
<footer>

View File

@ -1,7 +1,7 @@
{% unless page.no_header %}
<header>
{% if index %}
<h1 class="entry-title"><a href="{{ site.root }}{{ post.url }}">{{ post.title | titlecase }}</a></h1>
<h1 class="entry-title"><a href="{{ root_url }}{{ post.url }}">{{ post.title | titlecase }}</a></h1>
{% else %}
<h1 class="entry-title">{{ page.title | titlecase }}</h1>
{% endif %}
@ -11,10 +11,10 @@
</header>
{% endunless %}
{% if index %}
<div class="entry-content">{{ content | full_urls: site.root | exerpt | smart_quotes }}</div>
<div class="entry-content">{{ content | exerpt }}</div>
<footer>
<a rel="full-article" href="{{ site.root }}{{ post.url }}">Read on &rarr;</a>
<a rel="full-article" href="{{ root_url }}{{ post.url }}">Read on &rarr;</a>
</footer>
{% else %}
<div class="entry-content">{{ content | full_urls: site.root | smart_quotes }}</div>
<div class="entry-content">{{ content }}</div>
{% endif %}

View File

@ -12,7 +12,7 @@
var pinboardInit = document.createElement('script');
pinboardInit.type = 'text/javascript';
pinboardInit.async = true;
pinboardInit.src = '{{ site.root }}/javascripts/pinboard.js';
pinboardInit.src = '{{ root_url }}/javascripts/pinboard.js';
document.getElementsByTagName('head')[0].appendChild(pinboardInit);
})();
</script>

View File

@ -3,7 +3,7 @@
<ul id="recent_posts">
{% for post in site.posts limit: site.recent_posts %}
<li class="post">
<a href="{{ site.root }}{{ post.url }}">{{ post.title }}</a>
<a href="{{ root_url }}{{ post.url }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>

View File

@ -9,7 +9,7 @@
getTwitterFeed("{{site.twitter_user}}", {{site.twitter_tweet_count}}, {{site.twitter_show_replies}});
});
</script>
<script src="{{ site.root }}/javascripts/twitter.js" type="text/javascript"> </script>
<script src="{{ root_url }}/javascripts/twitter.js" type="text/javascript"> </script>
{% if site.twitter_follow_button %}
<a href="http://twitter.com/{{ site.twitter_user }}" class="twitter-follow-button" data-width="208px" data-show-count="{{ site.twitter_show_follower_count }}">Follow @{{ site.twitter_user }}</a>
{% else %}

View File

@ -19,14 +19,14 @@
<meta name="keywords" content="{{page.keywords}}"/>
{% endif %}
<link href="{{ site.root }}/favicon.png" rel="shortcut icon" />
<link href="{{ site.root }}/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="{{ site.root }}/javascripts/modernizr-2.0.js"></script>
<link href="{{ root_url }}/favicon.png" rel="shortcut icon" />
<link href="{{ root_url }}/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="{{ root_url }}/javascripts/modernizr-2.0.js"></script>
<script src="http://s3.amazonaws.com/ender-js/jeesh.min.js"></script>
<script src="{{ site.root }}/javascripts/octopress.js" type="text/javascript"></script>
<script src="{{ root_url }}/javascripts/octopress.js" type="text/javascript"></script>
<link href='http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic' rel='stylesheet' type='text/css'>
<link href="{{ site.root }}/atom.xml" rel="alternate" title="{{site.title}}" type="application/atom+xml"/>
<link href="{{ root_url }}/atom.xml" rel="alternate" title="{{site.title}}" type="application/atom+xml"/>
{% include google_analytics.html %}
{% include google_plus_one.html %}
{% include twitter_sharing.html %}

View File

@ -1,5 +1,5 @@
<hgroup>
<h1><a href="{{ site.root }}/">{{ site.title }}</a></h1>
<h1><a href="{{ root_url }}/">{{ site.title }}</a></h1>
{% if site.subtitle %}
<h2>{{ site.subtitle }}</h2>
{% endif %}

View File

@ -6,11 +6,11 @@
</ul>
<form action="{{ site.simple_search }}" method="get">
<fieldset role="site-search">
<input type="hidden" name="q" value="site:{{ site.url | search_url }}" />
<input type="hidden" name="q" value="site:{{ site.url | shorthand_url }}" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul role="navigation">
<li><a href="{{ site.root }}/">Blog</a></li>
<li><a href="{{ site.root }}/blog/archives">Archives</a></li>
<ul role=main-navigation>
<li><a href="{{ root_url }}/">Blog</a></li>
<li><a href="{{ root_url }}/blog/archives">Archives</a></li>
</ul>

View File

@ -1,10 +1,11 @@
{% capture root_url %}{{ site.root | strip_slash }}{% endcapture %}
{% include head.html %}
<body {% if page.body_id %} id="{{ page.body_id }}" {% endif %} {% if page.sidebar == false %} class="no-sidebar" {% endif %}>
<header>{% include header.html %}</header>
<nav>{% include navigation.html %}</nav>
<div id="main">
<div id="content">
{{ content }}
{{ content | expand_urls: root_url | smart_quotes }}
{% unless page.sidebar == false %}
<aside role=sidebar>{% include sidebar.html %}</aside>
{% endunless %}

View File

@ -8,7 +8,7 @@ layout: default
<h1 class="entry-title">{{ page.title | titlecase }}</h1>
{% if page.date %}<p class="meta">{% include post/date.html %}</p>{% endif %}
</header>
{{ content | full_urls: site.root | smart_quotes }}
{{ content }}
{% unless page.footer == false %}
<footer>
{% if page.date %}<p class="meta">{% include post/date.html %}</p>{% endif %}

View File

@ -14,13 +14,13 @@ footer: false
<nav role="pagination">
<div>
{% if paginator.next_page %}
<a class="prev" href="{{ site.root }}/page{{paginator.next_page}}/">&larr; Older</a>
<a class="prev" href="/page{{paginator.next_page}}/">&larr; Older</a>
{% endif %}
<a href="{{ site.root }}/blog/archives">Blog Archives</a>
<a href="/blog/archives">Blog Archives</a>
{% if paginator.previous_page and paginator.previous_page > 1 %}
<a class="next" href="{{ site.root }}/page{{paginator.previous_page}}/">Newer &rarr;</a>
<a class="next" href="/page{{paginator.previous_page}}/">Newer &rarr;</a>
{% elsif paginator.previous_page %}
<a class="next" href="{{ site.root }}/">Newer &rarr;</a>
<a class="next" href="/">Newer &rarr;</a>
{% endif %}
</div>
</nav>

View File

@ -130,7 +130,7 @@ module Jekyll
#
def category_links(categories)
dir = @context.registers[:site].config['category_dir']
root_url = @context.registers[:site].config['root']
root_url = @context.registers[:site].config['root'].sub(/\/$/, '')
categories = categories.sort!.map do |item|
"<a class='category' href='#{root_url}/#{dir}/#{item.gsub(/_|\W/, '-')}/'>#{item}</a>"
end

View File

@ -20,15 +20,23 @@ module OctopressFilters
end
# Replaces relative urls with full urls
def full_urls(input, url='')
url ||= ''
def expand_urls(input, url='')
url ||= '/'
input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]+)/ do
$1+url+$3
end
end
# Returns a url without the http:// for use in as a search modifier eg. 'search terms site:website.com'
def search_url(input)
# Removes trailing forward slash from a string for easily appending url segments
def strip_slash(input)
if input =~ /(.+)\/$|^\/$/
input = $1
end
input
end
# Returns a url without the protocol (http://)
def shorthand_url(input)
input.gsub /(https?:\/\/)(\S+)/ do
$2
end