-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes to Topics page #142
Comments
Another option would perhaps be to put the list of topic headings at the top of each page and make them links to the full topic profiles - something like "table of contents" in Word. --> when you click e.g. on "Alternative meat research and development" it moves you down to where the topic is described in full depth |
It looks like the content of that page is stored as HTML in the database. If that's true, there's no easy, reliable way to separate the headers from the rest of the content. Adding this process would be a bit of work, requiring changes to the database schema. I'm not familiar with how the app works, so I'm not really qualified to know whether this is something worth doing. Here's a quick and dirty, but fragile, solution in JavaScript: function slugify(text) {
return text.replace(/[^a-zA-Z]+/g, "-");
}
$(".all-tags p b").each(function(i, el) {
$(el).attr("id", slugify($(el).html()));
})
let introductoryParagraph;
$(".all-tags p").each(function (i, el) {
console.log($(el).html())
if ($(el).html().match(/There are several paths/)) {
introductoryParagraph = $(el);
return false;
}
});
let subsections = $("b");
introductoryParagraph.append("<br />")
introductoryParagraph.append("<ul class='hacky-table-of-contents'></ul>");
let hackyTableOfContents = $(".hacky-table-of-contents");
subsections.each(function (i, subsection) {
const text = $(subsection).html();
if (text) {
const slug = slugify(text);
hackyTableOfContents.append(`<li><a href="#${slug}">${text}</a></li>`);
}
}) |
Hey. The whole website is mostly server-side rendered, but the page is surely not "stored in the DB as HTML". Only the raw data are stored in the database, which is dynamically "templated" into the template when the page is requested. Creating table of contents would be somewhat easily done on the server side by sending it explicitly to the template and editing the template (@veselyvojtech just did something similar elsewhere, here it seems to be even easier), the JS seems too hackish and fragile indeed. Are you @patbl able to edit the server code too or not? Given you have written it already though, you can try that and deploy on beta to see how well it works. |
I can edit the server-side code. I thought that the descriptions were stored as raw HTML because that's what
I'll need to look at it a bit more thoroughly! I don't mind throwing away the JS code I wrote. I threw that together quickly, and suggested it only because I thought there wasn't an easy server-side solution. |
You are actually right @patbl, apologies on my side, I forgot that discipline fields are specified as a streamfield and therefore it will be hard to do much more on the server-side 🤦 (I have mistaken that with an old version where we had actual "topics" as individual objects). |
I don't have much more ideas than what you proposed on frontend. At least not easily. Let's open a PR, give it a shot on beta env and we'll see? Another way would be to make the model of the discipline "richer" by having explicit headings etc., but that doesn't seem ideal either and would require some data migrations. |
Hey @patbl - any updates on this? I also realized that the streamfield is indeed a big blob stored in the database, but not as a plain html text, but a structured JSON, so we should be able to get e.g. the tags or headlines out to populate the context. |
Sorry, I haven't gotten around to working on it yet. Thanks for the tip re JSON. I think I'll have an hour to work on it tomorrow, and some more time this weekend. |
@DavidJanku I tried to create that kind of outline (basically list of the links for the topics) by reusing the solution that was used for the The discipline snippet contained all the information in the
The generated outline is displayed under the I rewrote the discipline life sciences on beta to this format, you can take a look. |
Thanks @veselyvojtech, it looks good. The only problems I've spotted are:
|
Maybe two more changes - |
Problem:
The amount of text describing topic ideas for various disciplines (e.g. psychology or life sciences) seems to be too big, causing that one has to scroll a lot to find the topic they like.
Potential solution:
Make the text for each topic collapsable - i.e. after a few rows collapse the text and offer "read more" link or button.
This should work for each topic separately - like this
-- one idea how to do it is to enable creating multiple "paragraphs" (or bodies of text) in snippets Thesis disciplines, so I can copy each topic in a separate text body and then set the condition that all text bodies in snippets thesis discipline would collapse after X rows of text
The text was updated successfully, but these errors were encountered: