Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jekyll page that will list quotes in all the posts.
---
layout: page
title: Recent Blog Quotes
menu_title: Quotes
menu: true
order: 4
---
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script>
$(document).ready(function () {
var feed = "{{ site.baseurl }}/feed.xml";
$.ajax(feed, {
accepts: {
xml: "application/rss+xml"
},
dataType: "xml",
error: function (xhr, status, error) {
var contentsDiv = $("#contents");
contentsDiv.html(status+"<br/>"+error);
},
success: function (data) {
console.log(data);
var contentsDiv = $("#contents");
var quotesList = $("<ol></ol>").text("");
contentsDiv.empty();
contentsDiv.append(quotesList);
$(data).find("entry").each(function () {
var el = $(this);
console.log(el);
var title = el.find("title").text();
var link = el.find("link").attr('href');
var description = el.find("content").text();
var tag_regex = /(<([^>]+)>)/ig
var description2 = description.replace(/<br>/ig, '\n').replace(/<br\/>/ig, '\n').replace(/<br \/>/ig, '\n').replace(tag_regex, '');
var all_lines = description2.split("\n");
var lines = $.map(all_lines, function (v) {
return v === "" ? null : v;
});
if (lines.length > 0) {
var last_line_index = lines.length - 1;
var last_line = lines[last_line_index];
var has_quotes = false;
var quote_lines = "";
while (last_line_index >= 0 && last_line != null && last_line.charAt(0) == "\"") {
quote_lines = last_line + "<br/><br/>" + quote_lines;
last_line_index--;
last_line = lines[last_line_index];
has_quotes = true;
}
if (quote_lines.length > 0) {
var quoteContent = "<b><a href=\"" + link + "\">" + title + "</a></b><br/>" + quote_lines;
var quoteItem = $("<li></li>").html(quoteContent);
quotesList.append(quoteItem);
}
}
});
}
});
});
</script>
<div id="contents">Loading...</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.