Skip to content

Instantly share code, notes, and snippets.

@poritsky
Created January 10, 2012 15:29
Show Gist options
  • Save poritsky/1589613 to your computer and use it in GitHub Desktop.
Save poritsky/1589613 to your computer and use it in GitHub Desktop.
Way to add external links to post headers in Octopress.
{% unless page.no_header %}
<header>
{% if index %}
{% if post.external-url %}<!-- Assumes you use 'external-url:' in your YAML. Change to whatever you like as long as they match. -->
<h1 class="entry-title"><a href="{{ post.external-url }}">{% if site.titlecase %}{{ post.title | titlecase }}<!-- Glyph or label that this is a link post goes here -->{% else %}{{ post.title }}{% endif %}</a></h1>
{% else %}
<h1 class="entry-title"><a href="{{ root_url }}{{ post.url }}">{% if site.titlecase %}{{ post.title | titlecase }}{% else %}{{ post.title }}{% endif %}</a></h1>
{% endif %}
{% else %}
{% if page.external-url %}<!-- The above code changes the header on your index pages (list of posts). Now this will change the header on actual post pages so the header will still link out to an external url. -->
<h1 class="entry-title"><a href="{{ page.external-url }}">{% if site.titlecase %}{{ page.title | titlecase }}<!-- Glyph or label again -->{% else %}{{ page.title }}{% endif %}</a></h1>
{% else %}
<h1 class="entry-title">{% if site.titlecase %}{{ page.title | titlecase }}{% else %}{{ page.title }}{% endif %}</h1>
{% endif %}
{% endif %}
{% unless page.meta == false %}
<p class="meta">
{% include post/date.html %}{{ time }}
{% if site.disqus_short_name and page.comments != false and site.disqus_show_comment_count == true %}
| <a href="{% if index %}{{ root_url }}{{ post.url }}{% endif %}#disqus_thread">Comments</a>
{% endif %}
</p>
{% endunless %}
</header>
{% endunless %}
{% if index %}
<div class="entry-content">{{ content | excerpt }}</div>
{% capture excerpted %}{{ content | has_excerpt }}{% endcapture %}
{% if excerpted == 'true' %}
<footer>
<a rel="full-article" href="{{ root_url }}{{ post.url }}">{{ site.excerpt_link }}</a>
</footer>
{% endif %}
{% if post.external-url %}
<div class="entry-content"><a href="{{ root_url }}{{ post.url }}"><!-- Adds permalink text to go back to your site at bottom of post. --></a>
</div>
{% endif %}
{% if page.external-url %}
<div class="entry-content"><a href="{{ root_url }}{{ post.url }}"><!-- Same as above, this is to add permalink at end of individual post pages. 'Permalink' or other text goes here --></a>
</div>
{% endif %}
{% else %}
<div class="entry-content">{{ content }}</div>
{% endif %}
---
layout: nil
---
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[{{ site.title }}]]></title>
<link href="{{ site.url }}/atom.xml" rel="self"/>
<link href="{{ site.url }}/"/>
<updated>{{ site.time | date_to_xmlschema }}</updated>
<id>{{ site.url }}/</id>
<author>
<name><![CDATA[{{ site.author | strip_html }}]]></name>
{% if site.email %}<email><![CDATA[{{ site.email }}]]></email>{% endif %}
</author>
<generator uri="http://octopress.org/">Octopress</generator>
{% for post in site.posts limit: 20 %}
<entry>
{% if post.external-url %}
<title type="html"><![CDATA[{{ post.title | cdata_escape }}<!-- Put a glyph or label here if you want to denote that the link will lead to an external url. -->]]></title>
<link href="{{ post.external-url }}"/>
{% else %}
<title type="html"><![CDATA[{{ post.title | cdata_escape }}]]></title>
<link href="{{ site.url }}{{ post.url }}"/>
{% endif%}
<updated>{{ post.date | date_to_xmlschema }}</updated>
<id>{{ site.url }}{{ post.id }}</id>
<content type="html"><![CDATA[{{ post.content | expand_urls: site.url | cdata_escape }}]]></content>
</entry>
{% endfor %}
</feed>
---
layout: post
title: "Post Sample"
date:
comments: true
categories:
external-url: <!-- Whatever you call this is what you will use in the rest of your code. If it's 'foo' then use 'foo' later -->
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment