This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathincludable.xml
92 lines (90 loc) · 3.28 KB
/
includable.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<b:includable id='postRelated' data='post'>
<div id='wjs-related' class='wjs-related'/>
<script>
/*!
* wjs-related v2.1.0
* Copyright 2018 zkreations
* Developed by José Gregorio (fb.com/JGMateran)
* Licensed under MIT (github.com/zkreations/wjs-related/blob/master/LICENSE)
*/
var related = (function(){
'use strict';
//Configuracion
var defaults = {
id: '<data:post.id/>',
homepage: window.location.protocol + '//' + window.location.hostname,
image: 'src/imgdefault.jpg', //Imagen por defecto
length: 6, //Cantidad de entradas
localeDate: 'es-ES', //Idioma
snippet: 50, //Cantidad de texto
imgSize: 's256', //Recorte de la imagen
container: document.getElementById('wjs-related'),
tags: [<b:loop values='data:post.labels' var='label'>'<data:label.name/>',</b:loop>]
};
//<![CDATA[
var tags$length = defaults.tags.length;
var script = document.createElement( 'script' );
var src = defaults.homepage + '/feeds/posts/default' +
'?alt=json-in-script' +
'&callback=related' +
'&max-results=' + ( defaults.length + 1 ) +
'&q=';
for ( var n = 0; n < tags$length; n++ ){
src += 'label:"' + defaults.tags[ n ] + '"' + ( n === tags$length - 1 ? '' : '|' );
}
script.src = src;
document.body.appendChild( script );
function render( data ){
var title = data.title.$t;
var content = data.content;
var summary = data.summary;
var body = content ? content.$t : summary.$t;
var snippet = (body).replace(/<[^>]*>?/g,'').substring( 0, defaults.snippet ) + '...';
var img = data.media$thumbnail;
var tempHtml = document.createElement('div');
tempHtml.innerHTML = body;
var imgHtml = tempHtml.querySelector('img');
var image = ( img ? img.url : (imgHtml ? imgHtml.src : defaults.image)).replace(/[swh]\d{2,4}(?:-[swh]\d{2,4})?(?:-c)?/, defaults.imgSize);
var url = (function(){
for ( var i = 0; i < data.link.length; i++ ){
var link = data.link[i];
if ( link.rel === 'alternate' ){
return link.href;
}
}
})();
var published = new Date( data.published.$t ).toLocaleDateString(
defaults.localeDate,
{year:'numeric', month:'long', day: 'numeric'}
);
return (
'<div class="relCard">'+
'<div class="relCard-content">'+
'<a href="' + url + '" class="relCard-image">'+
'<img src="' + image + '" alt="' + title + '" />'+
'</a>'+
'<div class="relCard-data">'+
'<h3 class="relCard-title">' + title + '</h3>'+
'<div class="relCard-date">' + published + '</div>'+
'<p class="relCard-snippet">' + snippet + '</p>'+
'</div>'+
'</div>'+
'</div>'
);
}
function related( json ){
var i = 0;
var post;
var length = defaults.length;
for ( ; i < length && ( post = json.feed.entry[ i ] ); i++ ){
if ( defaults.id !== post.id.$t.split( '.post-' )[ 1 ] ){
defaults.container.innerHTML += render( post );
} else {
length++;
}
}
}
return related;
})();
//]]></script>
</b:includable>