[Feature Request] Auto-sort when adding new feeds
NightHawkATL opened this issue · 1 comments
NightHawkATL commented
Is your feature request related to a problem? Please describe.
Sort of..
Describe the solution you'd like
I am coming from FresshRSS which would auto-sort alphabetically and I wouldn't have to worry about position within categories. I would like to request the same for Commafeed.
Describe alternatives you've considered
manually configuring each feed (time consuming when you have over 100 feeds).
Additional context
Add any other context or screenshots about the feature request here.
Jorengarenar commented
That would be indeed neat.
As a workaround, for now, I propose the following to be pasted into Custom code:
function sortByTitle(parent) {
const nodes = Array.from(parent.children).sort((a, b) => {
const at = a.getAttribute("text").toLowerCase();
const bt = b.getAttribute("text").toLowerCase();
if (at < bt) return -1;
if (at > bt) return 1;
return 0;
});
nodes.forEach(sortByTitle);
parent.replaceChildren(...nodes);
}
function getOpml() {
return fetch(window.location.origin + "/rest/feed/export")
.then((res) => res.text())
.then((str) => new window.DOMParser().parseFromString(str, "text/xml"));
}
function postOpml(opml) {
const opmlText = new XMLSerializer().serializeToString(opml);
const opmlFile = new File([opmlText], "rss.opml", { type: "text/xml" });
const formData = new FormData();
formData.append("file", opmlFile);
fetch(window.location.origin + "/rest/feed/import", {
method: "POST",
body: formData,
});
}
async function sortFeeds() {
const xml = await getOpml();
sortByTitle(xml.children[0].children[1]);
postOpml(xml);
}
// sortFeeds();
/* 1. add feed
* 2. uncomment the above function
* 3. refresh page
* 4. comment the function back
* 5. feeds are sorted
*/