Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Apr 27, 2015
1 parent b7c671f commit 5151143
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
twitter_format: "@title: @url@tags"
twitter_url_length: 22
twitter_max_length: 140
64 changes: 64 additions & 0 deletions _layouts/social-feed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
layout: social-feed
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ site.blog_title | xml_escape }}</title>
<description>{{ site.blog_description | xml_escape }}</description>
<link>{{ site.site_url }}{{ site.blog_url }}</link>
<atom:link href="{{ "/feed.xml" | prepend: site.blog_url | prepend: site.site_url }}" rel="self" type="application/rss+xml" />
<pubDate>{{ site.time | date_to_rfc822 }}</pubDate>
<lastBuildDate>{{ site.time | date_to_rfc822 }}</lastBuildDate>
<generator>Jekyll v{{ jekyll.version }}</generator>
{% assign site.twitter_format = "@title: @url@tags" %}
{% assign site.site.twitter_url_length = 22 %}
{% assign twitter_max_length = 140 %}

{% assign platform = page.title | downcase %}

{% for post in site.posts limit:10 %}
{% assign share_on = post.share | downcase %}

{% if share_on contains '--twitter-hashtags' %}
{% assign format_parsed = site.twitter_format | replace: '@title', post.title | replace: '@url', '' | replace: '@tags', '' | size %}
{% assign post_tags = '' %}
{% assign space_left = site.twitter_max_length | minus: format_parsed.size %}

{% if site.twitter_format contains '@url' %}
{% assign space_left = space_left | minus: site.twitter_url_length %}
{% endif %}

{% for tag in post.tags %}
{% capture new_tag %} #{{ tag }}{% endcapture %}
{% assign new_space_left = space_left | minus: new_tag.size %}

{% if new_space_left > 0 %}
{% assign post_tags = post_tags | append: new_tag %}
{% assign space_left = space_left | minus: new_tag.size %}
{% endif %}
{% endfor %}

{% assign post_title = site.twitter_format | replace: '@title', post.title | replace: '@tags', post_tags | replace: '@url', post.url %}
{% else %}
{% assign post_title = post.title %}
{% endif %}

{% if share_on contains platform %}
<item>
<title>{{ post_title | xml_escape }}</title>
<description>{{ post.content | xml_escape }}</description>
<pubDate>{{ post.date | date_to_rfc822 }}</pubDate>
<link>{{ post.url | prepend: site.site_url }}</link>
<guid isPermaLink="true">{{ post.url | prepend: site.site_url }}</guid>
{% for tag in post.tags %}
<category>{{ tag | xml_escape }}</category>
{% endfor %}
{% for cat in post.categories %}
<category>{{ cat | xml_escape }}</category>
{% endfor %}
</item>
{% endif %}
{% endfor %}
</channel>
</rss>
9 changes: 9 additions & 0 deletions _posts/2015-04-28-example-post.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
layout: post
title: "Example post"
date: 2015-04-28 09:32:00
categories: blog
tags: jekyll social example post
share: twitter --twitter-hashtags facebook linkedin
---
Hello world
4 changes: 4 additions & 0 deletions social-feeds/facebook.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: social-feed
title: Facebook
---
4 changes: 4 additions & 0 deletions social-feeds/linkedin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: social-feed
title: LinkedIn
---
60 changes: 60 additions & 0 deletions social-feeds/twitter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
layout: null
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ site.blog_title | xml_escape }}</title>
<description>{{ site.blog_description | xml_escape }}</description>
<link>{{ site.site_url }}{{ site.blog_url }}</link>
<atom:link href="{{ "/feed.xml" | prepend: site.blog_url | prepend: site.site_url }}" rel="self" type="application/rss+xml" />
<pubDate>{{ site.time | date_to_rfc822 }}</pubDate>
<lastBuildDate>{{ site.time | date_to_rfc822 }}</lastBuildDate>
<generator>Jekyll v{{ jekyll.version }}</generator>
{% assign platform = 'twitter' %}

{% for post in site.posts limit:10 %}
{% assign share_on = post.share | downcase %}

{% if share_on contains '--twitter-hashtags' %}
{% assign format_parsed = site.twitter_format | replace: '@title', post.title | replace: '@url', '' | replace: '@tags', '' | size %}
{% assign post_tags = '' %}
{% assign space_left = site.twitter_max_length | minus: format_parsed.size %}

{% if site.twitter_format contains '@url' %}
{% assign space_left = space_left | minus: site.twitter_url_length %}
{% endif %}

{% for tag in post.tags %}
{% capture new_tag %} #{{ tag }}{% endcapture %}
{% assign new_space_left = space_left | minus: new_tag.size %}

{% if new_space_left > 0 %}
{% assign post_tags = post_tags | append: new_tag %}
{% assign space_left = space_left | minus: new_tag.size %}
{% endif %}
{% endfor %}

{% assign post_title = site.twitter_format | replace: '@title', post.title | replace: '@tags', post_tags | replace: '@url', post.url %}
{% else %}
{% assign post_title = post.title %}
{% endif %}

{% if share_on contains platform %}
<item>
<title>{{ post_title | xml_escape }}</title>
<description>{{ post.content | xml_escape }}</description>
<pubDate>{{ post.date | date_to_rfc822 }}</pubDate>
<link>{{ post.url | prepend: site.site_url }}</link>
<guid isPermaLink="true">{{ post.url | prepend: site.site_url }}</guid>
{% for tag in post.tags %}
<category>{{ tag | xml_escape }}</category>
{% endfor %}
{% for cat in post.categories %}
<category>{{ cat | xml_escape }}</category>
{% endfor %}
</item>
{% endif %}
{% endfor %}
</channel>
</rss>

0 comments on commit 5151143

Please sign in to comment.