Skip to content

Instantly share code, notes, and snippets.

@andrejarrell andrejarrell/posts.js
Last active Oct 10, 2019

Embed
What would you like to do?
Updates posts on my website: https://andre.gg/posts
$(function() {
const getContent = (site, num) => {
$.get(`https://${site}.andre.gg/feed.json`, d => {
for (i=0; i<num; i++) {
$(`.${site}-title-${i+1}`).html(`<a class="${site}-title-${i+1}" href="${d.items[i].url.replace('.html', '')}" target="_blank">${d.items[i].title}</a>`);
$(`.${site}-date-${i+1}`).text(date(d.items[i].date_published));
$(`.${site}-url-${i+1}`).attr('href', d.items[i].url.replace('.html', ''));
$(`.${site}-image-${i+1}`).attr('src', d.items[i].image);
};
});
};
const date = t => `${t.slice(5,7)}/${t.slice(8,10)}/${t.slice(0,4)}`;
const init = () => {
getContent('blog', 3);
getContent('js', 3);
};
init();
});
@andrejarrell

This comment has been minimized.

Copy link
Owner Author

commented Oct 10, 2019

$(function() {
    const getContent = (site, num) => {
        $.get(`https://${site}.andre.gg/feed.json`, d => {
        for (i=0; i<num; i++) {
            $(`.${site}-title-${i+1}`).html(`<a class="${site}-title-${i+1}" href="${d.items[i].url.replace('.html', '')}" target="_blank">${d.items[i].title}</a>`);
            $(`.${site}-date-${i+1}`).text(date(d.items[i].date_published));
            $(`.${site}-url-${i+1}`).attr('href', d.items[i].url.replace('.html', ''));
            $(`.${site}-image-${i+1}`).attr('src', d.items[i].image);
        };
    });
  };

  const date = t => `${t.slice(5,7)}/${t.slice(8,10)}/${t.slice(0,4)}`;
  
  const init = () => {
    getContent('blog', 3);
    getContent('js', 3);
  };
  
  init();
});
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.