Spez I wouldn't have a clue how to help you with this issue, however in case it could be of some use for you, here is an (experimental) dynamic structured data script that I've recently been attempting to wrap the mind around:
<script type="application/ld+json">
(function() {
// Function to extract discussion data
function getDiscussions() {
const discussions = [];
const discussionItems = document.querySelectorAll('.DiscussionListItem'); // NOTE: Unsure if this selector is correct.
discussionItems.forEach(item => {
const title = item.querySelector('.DiscussionListItem-title').innerText; // NOTE: Unsure if this selector is correct.
const url = item.querySelector('a').href; // NOTE: Unsure if this selector is correct.
const author = item.querySelector('.DiscussionListItem-author').innerText; // NOTE: Unsure if this selector is correct.
const dateCreated = item.querySelector('.item-terminalPost').innerText; // NOTE: Unsure if this selector is correct.
// Initialize comments array
const comments = getComments(item); // Call function to extract comments for this discussion.
discussions.push({
title: title,
url: url,
author: author,
dateCreated: new Date(dateCreated).toISOString(), // Convert to ISO format.
comments: comments // Add comments to the discussion object.
});
});
return discussions;
}
// Function to extract comments for a specific discussion
function getComments(discussionItem) {
const comments = [];
const commentItems = discussionItem.querySelectorAll('.PostStream-item'); // NOTE: Unsure if this selector is correct.
commentItems.forEach(commentItem => {
const commentText = commentItem.querySelector('.CommentPost').innerText; // NOTE: Unsure if this selector is correct.
const commenterName = commentItem.querySelector('.item-user').innerText; // NOTE: Unsure if this selector is correct.
const commentDate = commentItem.querySelector('.item-meta').innerText; // NOTE: Unsure if this selector is correct.
comments.push({
text: commentText,
commenter: commenterName,
dateCreated: new Date(commentDate).toISOString() // Convert to ISO format.
});
});
return comments;
}
const discussions = getDiscussions();
const structuredData = {
"@context": "https://schema.org",
"@type": "DiscussionForum",
"name": "Anomalum",
"url": "https://anomalum.flarum.cloud",
"discussion": discussions.map(discussion => ({
"@type": "Discussion",
"name": discussion.title,
"url": discussion.url,
"author": {
"@type": "Person",
"name": discussion.author
},
"dateCreated": discussion.dateCreated,
"comment": discussion.comments.map(comment => ({
"@type": "Comment",
"text": comment.text,
"author": {
"@type": "Person",
"name": comment.commenter
},
"dateCreated": comment.dateCreated
}))
}))
};
// Create a script element to hold the structured data
const script = document.createElement('script');
script.type = 'application/ld+json';
script.text = JSON.stringify(structuredData);
document.head.appendChild(script); // Append to the head instead of writing to the document
})();
</script>
• Please do note: This is not a proven code.
•I honestly don't know what the correct selectors should be for something like this yet, and frankly I simply wouldn't know whether this code could even work at all. Hopefully it will work with the appropriate adjustments though.