-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcategory.html
More file actions
executable file
·166 lines (144 loc) · 5.97 KB
/
category.html
File metadata and controls
executable file
·166 lines (144 loc) · 5.97 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
---
layout: default
---
<link rel="stylesheet" href="{{ site.baseurl }}/css/custom/category.css">
<div class="max-w-4xl mx-auto px-4 md:px-12 py-8 md:py-12">
{% assign default_lang = site.default_lang | default: 'ko' %}
{% assign visible_categories_count = 0 %}
{% for category in site.categories %}
{% assign localized_posts_count = 0 %}
{% for post in category[1] %}
{% if post.lang == nil or post.lang == '' or post.lang == default_lang %}
{% assign localized_posts_count = localized_posts_count | plus: 1 %}
{% endif %}
{% endfor %}
{% if localized_posts_count > 0 %}
{% assign visible_categories_count = visible_categories_count | plus: 1 %}
{% endif %}
{% endfor %}
<div class="category-header">
<h1>Category</h1>
<p>현재까지 {{ visible_categories_count }}개의 주제를 다루고 있습니다.</p>
</div>
<div class="category-tags">
{% for category in site.categories %}
{% assign localized_posts_count = 0 %}
{% for post in category[1] %}
{% if post.lang == nil or post.lang == '' or post.lang == default_lang %}
{% assign localized_posts_count = localized_posts_count | plus: 1 %}
{% endif %}
{% endfor %}
{% if localized_posts_count > 0 %}
<a href="#{{ category | first | slugify }}" class="category-tag">
{{ category | first }}
<span class="category-tag-count">({{ localized_posts_count }})</span>
</a>
{% endif %}
{% endfor %}
</div>
<div class="category-sections">
{% for category in site.categories %}
{% assign localized_posts_count = 0 %}
{% for post in category[1] %}
{% if post.lang == nil or post.lang == '' or post.lang == default_lang %}
{% assign localized_posts_count = localized_posts_count | plus: 1 %}
{% endif %}
{% endfor %}
{% if localized_posts_count > 0 %}
<section id="{{ category | first | slugify }}" class="category-section">
<h2 class="category-section-title">
{{ category | first }} ({{ localized_posts_count }})
</h2>
<div class="category-posts">
{% assign sorted_posts = category[1] | sort: 'date' | reverse %}
{% for post in sorted_posts %}
{% if post.lang == nil or post.lang == '' or post.lang == default_lang %}
<div class="category-post-item">
<a href="{{ site.baseurl }}{{ post.url }}" class="category-post-link">
{{ post.title }}
</a>
<time datetime="{{ post.date | date_to_xmlschema }}" class="category-post-date">
{{ post.date | date: "%Y년 %m월 %d일" }}
</time>
</div>
{% endif %}
{% endfor %}
</div>
</section>
{% endif %}
{% endfor %}
</div>
</div>
<script>
document.querySelectorAll('.category-tag[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
const targetElement = document.getElementById(targetId);
if (targetElement) {
document.querySelectorAll('.category-tag').forEach(tag => {
tag.classList.remove('active');
});
this.classList.add('active');
const headerOffset = 80;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
});
});
function updateActiveTag() {
const sections = document.querySelectorAll('.category-section');
const tags = document.querySelectorAll('.category-tag[href^="#"]');
const headerOffset = 100;
let currentSection = '';
sections.forEach(section => {
const sectionTop = section.getBoundingClientRect().top;
const sectionId = section.getAttribute('id');
if (sectionTop <= headerOffset && sectionTop >= -200) {
currentSection = sectionId;
}
});
tags.forEach(tag => {
tag.classList.remove('active');
});
if (currentSection) {
const activeTag = document.querySelector(`.category-tag[href="#${currentSection}"]`);
if (activeTag) {
activeTag.classList.add('active');
}
}
}
let scrollTimeout;
window.addEventListener('scroll', function() {
if (scrollTimeout) {
clearTimeout(scrollTimeout);
}
scrollTimeout = setTimeout(updateActiveTag, 100);
});
updateActiveTag();
function shuffleCategoryGroups() {
var container = document.querySelector('.category-sections');
var tagContainer = document.querySelector('.category-tags');
if (!container || !tagContainer) return;
var sections = Array.from(container.querySelectorAll('.category-section'));
var tags = Array.from(tagContainer.querySelectorAll('.category-tag'));
var pairs = sections.map(function(section, i) {
return { section: section, tag: tags[i] };
});
for (var i = pairs.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = pairs[i];
pairs[i] = pairs[j];
pairs[j] = temp;
}
pairs.forEach(function(pair) {
container.appendChild(pair.section);
tagContainer.appendChild(pair.tag);
});
}
shuffleCategoryGroups();
</script>