Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
구글 블로거에 목차 페이지를 생성해 주는 스크립트입니다. 새 페이지를 생성해서 아래 코드를 넣으시면 됩니다. Google blogger index page from labels. This template generate a index page with post's labels. Create new page in blogger. And then copy and paste this code into page.
<div id="index_category"></div>
<div id="index_main"></div>
<script src="http://codeorigin.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
// categories 변수에 원하는 label을 넣으세요.
// 부모 카테고리 : [자식 카테고리 0..n]
// The categories should contain category labels that you want to display in index page.
// parent_category : [child_categories 0..n]
// live example : http://www.dorajistyle.pe.kr/p/bookshelf.html
var categories = {'여행': ['준비'],
'대한민국': ['서울','인천','대전','대구','울산','광주','부산',
'경기도','강원도','충청남도','충청북도',
'전라남도','전라북도','경상남도','경상북도','제주도'],
'유럽': ['이탈리아','스페인','프랑스','독일','영국','아일랜드','노르웨이',
'스웨덴','오스트리아','헝가리','슬로바키아'],
'아시아': ['중국','일본','태국','라오스','베트남','말레이시아','필리핀'],
'중동': ['터키','시리아','요르단'],
'아프리카': ['이집트'],
'북미': ['미국','캐나다'],
'남미': [''],
'오세아니아': [''],
'책': ['수필','소설','희곡','시','철학','명상','건강',
'사회','창작기술','자기계발','기술','기타'],
'지식': ['언어','사회','철학','기타'],
'건강': ['식사','운동','명상','기타'],
'영화': ['대한민국','영국','미국','프랑스','이탈리아',
'스웨덴','독일','루마니아','홍콩','인도'],
'드라마': ['대한민국','국외'],
'음악': ['재즈','록','힙합','팝','어쿠스틱','트랜스','기타'],
'공연': ['연극','뮤지컬','음악','춤'],
'전시': ['예술'],
'콘퍼런스': ['기타'],
'조리법': ['요리','활동식','음료'],
'사용기': ['전자제품', '음향', '기타'],
'동물': ['고양이'],
'IT': ['web','db','sccm','testing','blog','browser','linux',
'windows','3D','Java','mobile','설치','환경','설정',
'방법론','이론','tip','app','etc'],
'취미': ['사진', '자전거','무술','수영','다이빙','춤',
'술','음악'],
'월풍': ['독백','일기','철학','창작','기타']
};
function getIndex(json, main, subs) {
var list_items = [];
if(json.feed.entry != undefined) {
for (var i = 0; i < json.feed.entry.length; i++) {
for (var j = 0; j < json.feed.entry[i].link.length; j++) {
if (json.feed.entry[i].link[j].rel == 'alternate') {
break;
}
}
var entryUrl = "'" + json.feed.entry[i].link[j].href + "'";
var entryTitle = json.feed.entry[i].title.$t;
var categories =json.feed.entry[i].category;
console.log('categories : '+categories);
$.each(subs, function(idx,sub) {
if(list_items[sub] == undefined) list_items[sub] = '';
var term = -1;
$.each(categories, function(cidx,category){
console.log('cidx : '+cidx+', category : '+category.term+', sub :'+sub);
if(category.term == sub) {
term = 1;
return;
}
});
if(term > -1) {
var item = "<li>" + "<a rel='bookmark' href="+ entryUrl + '" target="_blank">' + entryTitle + "</a> </li>";
list_items[sub]+=item;
}
});
}
$.each(subs, function(idx,sub) {
var prefix= '<div id="'+main+'_'+sub+'_list"><ul>';
var postfix = '</ul></div>';
console.log('content : '+ list_items[sub]);
$('#'+main+'_'+sub+'_list').replaceWith(prefix+list_items[sub]+postfix);
});
}
}
var cat_contents = '<div id="index_category">';
var main_contents = '<div id="index_main">';
$.each(categories, function(main,subs) {
console.log("cat - "+main+" : "+subs);
cat_contents += '<h2><span class="ds-icon menu-icon menu-icon-notice fl"></span><span class="emp"><b><a href="#'+main+'_category"></a>'+main+'</b></span><ul>';
main_contents += '<h2 id="'+main+'_cateogry"><span class="ds-icon menu-icon menu-icon-notice fl"></span><span class="emp"><b>'+main+'</b></span></h2>';
$.each(subs, function(idx,sub) {
cat_contents+= '<li><h3><a href="#'+main+'_'+sub+'_category">'+sub+'</a></h3></li>';
main_contents+= '<h3 id="'+main+'_'+sub+'_category">'+sub+'</h3><div id="'+main+'_'+sub+'_list"></div><br/>';
});
cat_contents += '</ul><br/>';
});
cat_contents += '</div><br/><hr/>';
main_contents += '</div>';
$('#index_category').replaceWith(cat_contents);
$('#index_main').replaceWith(main_contents);
$.each(categories, function(main,subs) {
console.log("cat - "+main+" : "+subs);
$.getJSON('http://www.dorajistyle.pe.kr/feeds/posts/summary/-/'+main+'?orderby=published&max-results=99999&alt=json')
.done(function (data) {
console.log("success!!!");
console.log(data);
getIndex(data, main, subs);
}).fail(function (xhr,textStatus) {
console.log("fail : " + xhr);
console.log("because : "+ textStatus);
});
});
</script>
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.