This should only show the number of pages visible to you, the current user. |
<div id="publicSpacesTable">Loading...</div> <script> (async function() { const tableContainer = document.getElementById('publicSpacesTable'); tableContainer.innerHTML = 'Fetching spaces...'; async function fetchAllSpaces(start = 0, limit = 50, accumulated = []) { const res = await fetch(`/rest/api/space?limit=${limit}&start=${start}`); const data = await res.json(); const all = accumulated.concat(data.results); if (data._links.next) { return fetchAllSpaces(start + limit, limit, all); } return all; } async function getSpaceLabels(spaceKey) { const res = await fetch(`/rest/api/space/${spaceKey}/label`); const data = await res.json(); return data.results.map(label => label.name); } async function countPagesInSpace(spaceKey) { const res = await fetch(`/rest/api/search?cql=space=${spaceKey}+AND+type=page&limit=1`); const data = await res.json(); return data.totalSize || 0; } try { const allSpaces = await fetchAllSpaces(); const publicSpaces = []; for (const space of allSpaces) { const labels = await getSpaceLabels(space.key); if (labels.includes('public')) { const pageCount = await countPagesInSpace(space.key); publicSpaces.push({ name: space.name, key: space.key, link: space._links.webui, count: pageCount }); } } if (publicSpaces.length === 0) { tableContainer.innerHTML = '<p>No public spaces found.</p>'; return; } const table = document.createElement('table'); table.style.borderCollapse = 'collapse'; table.style.width = '100%'; const headerRow = table.insertRow(); ['Space Name', 'Page Count'].forEach(text => { const th = document.createElement('th'); th.innerText = text; th.style.borderBottom = '1px solid #ccc'; th.style.textAlign = 'left'; th.style.padding = '6px'; headerRow.appendChild(th); }); for (const space of publicSpaces) { const row = table.insertRow(); const nameCell = row.insertCell(); const link = document.createElement('a'); link.href = space.link; link.target = '_blank'; link.innerText = space.name; nameCell.appendChild(link); nameCell.style.padding = '6px'; const countCell = row.insertCell(); countCell.innerText = space.count; countCell.style.padding = '6px'; } tableContainer.innerHTML = ''; tableContainer.appendChild(table); } catch (error) { console.error(error); tableContainer.innerHTML = 'Error fetching public spaces.'; } })(); </script> |