아니, 아니, 무료예요
.
수정:
이 스크립트는 테마 컴포넌트에 설치할 수 있습니다.
이 스크립트는 카테고리 목록의 항목을 해당 페이지 내에서만 정렬합니다.
호환성을 더 잘 유지하기 위해 어떤 템플릿이나 내부 구조에도 영향을 미치지 않습니다.
사용 중인 테마에 따라 조정이 필요할 수 있습니다.
사용하시는 환경에서 잘 작동하는지 알려주세요.
js
<script type="text/discourse-plugin" version="0.8">
api.onPageChange((url, title) => {
const { defaultHomepage } = require('discourse/lib/utilities');
if (url !== '/categories' && (url !== '/' || defaultHomepage() !== 'categories')) {
return;
}
const desktop_category_page_style = api.container.lookup('service:site-settings').desktop_category_page_style;
const sort = ({parent, nodes, selector}) => {
if (!parent || !nodes.length) {
return
}
Array.from(nodes).sort((a, b) => {
const valueA = a.querySelector(selector).textContent;
const valueB = b.querySelector(selector).textContent;
return valueB - valueA;
})
.forEach(row => parent.appendChild(row));
}
if (desktop_category_page_style.startsWith('categories')) {
const parent = document.querySelector('.category-list tbody[aria-labelledby="categories-only-category"]');
sort({
parent: parent,
nodes: parent?.querySelectorAll('tr'),
selector: 'td.topics span.value'
})
}
else if (desktop_category_page_style === 'subcategories_with_featured_topics') {
const childs = document.querySelectorAll('table.category-list');
sort({
parent: childs[0]?.parentElement,
nodes: childs,
selector: 'th.parent-category span.value'
})
} else {
// boxes doesn't have a count displayed
}
});
</script>