mitodl / ocw-studio

Open Source Courseware authoring tool
BSD 3-Clause "New" or "Revised" License
9 stars 3 forks source link

Resource and Course collections URLs use a mix of underscores and dashes #947

Open pdpinch opened 2 years ago

pdpinch commented 2 years ago

The path for Resource collections is /resource_collections/ but the slug for Resource Collection pages substitutes spaces with dashes. This leads to confusing URLs like https://ocw-draft-qa.global.ssl.fastly.net/resource_collections/open-textbooks/ and https://ocw-draft-qa.global.ssl.fastly.net/course_collections/open-learning-library/

Acceptance Criteria:

alicewriteswrongs commented 2 years ago

I think resource_collections in that URL comes from the name property of the collection (see https://github.com/mitodl/ocw-hugo-projects/blob/main/ocw-www/ocw-studio.yaml#L21) so I think we could change that to resource-collections but I'm not sure what precisely all the consequences would be of changing that right now

I think definitely good to do this before we go live and links need to be final, if we're going to do it

@gumaerc might have some thoughts about changing the name on a collection and what consequences that would have downstream

alicewriteswrongs commented 2 years ago

I have been meaning to ask if there's a better name we want in the URL, like whether course collections should be under collections or learning-paths or something like that

gumaerc commented 2 years ago

The name on a collection determines the content_type key stored in the front matter of the published content. This used to affect the type property in the front matter, which would change Hugo rendering behavior but it was moved to content_type specifically to avoid that. When importing, content_type is brought into the WebsiteContent objects as type. What will determine how Hugo outputs the content and thus the final URL of the content is the folder setting. For instance, resource collections has folder: content/resource_collections. The part of the path beyond content is what determines the folder it will go into in the Hugo content and subsequently the folder Hugo will output HTML into.

alicewriteswrongs commented 2 years ago

right folder!

Am I right in thinking that if we changed the folder props to be resource-collections and course-collections on the ocw-www configs, then all we would need to do is rename the folders from resource_collections to resource-collections (and similarly course_collections -> course-collections) in the theme before republishing?

alicewriteswrongs commented 2 years ago

by folders in the theme, I mean doing something like the following:

mv www/layouts/course_collections www/layouts/course-collections
gumaerc commented 2 years ago

In theory that would work, yea. Keep in mind that in some scenarios Hugo has trouble with hypens in filenames and / or metadata keys though. For instance, this code would not work:

{{ $courseCollections := $.Site.Data.course.course-collections }}

It would give you an error about - being an illegal character. In your example though, I think it would work because we're not calling out course-collections anywhere explicitly within the template, we're just setting up a layout and as long as the folder in the given site's content folder matches then you should be good. I would test it out though, obviously.

alicewriteswrongs commented 2 years ago

Ok, that all makes sense to me. If we want to go forward with this rename it would need to happen in ocw-hugo-themes and in ocw-hugo-projects (and then we could have some corresponding changes in our checked in files in this repo)