Mighil

bear blog dashboard post counter plugin

Here's a simple JavaScript snippet that automatically counts your published posts and drafts on your Bear Blog dashboard.

Installation

  1. Go to your Bear Blog dashboard
  2. Navigate to /dashboard/customise/
  3. Find the "Dashboard footer content:" section
  4. Paste the JavaScript snippet below
  5. Save

What it does

Code

<script>
// Count and display total posts and drafts
(function() {
    const postList = document.querySelector('ul.post-list');
    if (postList) {
        const allPosts = postList.querySelectorAll('li');
        const totalCount = allPosts.length;

        // Count drafts (posts with "not published" text)
        let draftCount = 0;
        allPosts.forEach(post => {
            const smallElement = post.querySelector('small');
            if (smallElement && smallElement.textContent.includes('not published')) {
                draftCount++;
            }
        });

        const publishedCount = totalCount - draftCount;

        const h1Element = document.querySelector('main h1');
        if (h1Element) {
            const countSpan = document.createElement('span');
            countSpan.textContent = ` (${publishedCount} published, ${draftCount} drafts)`;
            countSpan.style.fontSize = '0.8em';
            countSpan.style.fontWeight = 'normal';
            countSpan.style.color = '#777';
            h1Element.appendChild(countSpan);
        }
    }
})();
</script>

Contribute to bear plugins

You can contribute your own scripts at github.com/HermanMartinus/bear-plugins. This plugin is pending review via PR. I'd also like to extend a special thank you to Robert for bringing the Bear plugins GitHub repo to my attention and for checking if I might be interested in contributing.

Tagged in bear blog, tech