Skip to content

Instantly share code, notes, and snippets.

View marcelotten's full-sized avatar

Marcel Otten marcelotten

View GitHub Profile
@marcelotten
marcelotten / truncate.js
Last active December 15, 2015 23:59
Truncates the text of an element till the elements fits the given size using jQuery. But instead of just cutting the last characters it takes it from the middle which is more useful in most cases.
function truncate(elem, size){
var text = elem.text(), mid = Math.round(text.length/2), i = 0;
while(elem.width() > size){
i++;
var newText = text.substr(0,mid-1*i)+'…'+text.substr(mid+1*i, text.length);
elem.text(newText);
}
}
@marcelotten
marcelotten / itunesfeed.php
Created July 27, 2012 09:14
Kirby iTunes-Feed
<?php
// get any list of items
// in this case we get all visible children of the blog section,
// flip them to get them in reverse order and make sure we only get the last 10
$items = $pages->find($page->podcast())->children()->visible()->flip()->limit(25);
$podcast = $pages->find($page->podcast());
// defaults
if(!isset($descriptionExcerpt)) $descriptionExcerpt = true;
@marcelotten
marcelotten / sitemap.php
Created July 3, 2012 15:13
Kirby XML-Sitemap
<?php
header('Content-type: text/xml; charset="utf-8"');
echo '<?xml version="1.0" encoding="utf-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach($pages->index() as $p): ?>
<?php if($p->isVisible()): ?>