swiftlang / swift-org-website

Swift.org website
https://swift.org
Other
475 stars 187 forks source link

Consider adding redirects to evolution proposals that only require the proposal identifier #367

Open dempseyatgithub opened 1 year ago

dempseyatgithub commented 1 year ago

A request came up in the forums for a way to link to swift evolution proposals that uses only the proposal identifier and not the full title slug that is used in the GitHub repository: https://forums.swift.org/t/se-code-only-links-to-swift-evolution-proposal-files/66843

@xwu reached out from the language steering group to see if it would be possible to add redirects on swift.org that would do this.

For example, to reach the URL: https://github.com/apple/swift-evolution/blob/main/proposals/0406-async-stream-backpressure.md

which requires knowledge of the exact title slug 0406-async-stream-backpressure of the proposal filename,

a redirect would be hosted by swift.org, something like:

https://swift.org/proposals/0406.html

or

https://swift.org/proposals/SE-0406.html

which would redirect to the proposal on GitHub

Adding this would allow easier construction or automation of URLs to proposals.

dempseyatgithub commented 1 year ago

A few initial thoughts about this:

Currently the Swift Evolution dashboard page gets the parsed data as a JSON file and dynamically generates the bulk of the page in a client-side JavaScript, which also handles all the searching and filtering on the page.

For a set of redirects, it would make more sense to process the JSON file and create the redirects while the site itself was being statically generated. (Alternately, it may be easier to query GitHub directly to get the contents of the proposals directly, which has all the necessary info)

Since this would happen at site generation we may need to create a custom jekyll plug-in or run some kind of preprocessing script. I believe all redirects in vanilla jekyll are handled as client-side meta refreshes, so we would need one actual html file per proposal. I think it would be preferable to have a server-side redirect, so that would require some investigation.

// @alexandersandberg

alexhunsley commented 1 year ago

Thanks for filing this @dempseyatgithub. I can help implement this if possible. I guess before anything is done, a decision about the best implementation strategy needs making.

alexhunsley commented 1 year ago

I've just had a look inside the js for the proposals search screen at https://www.swift.org/swift-evolution. Could SE proposal code redirects be handled upon loading a dashboard URL like https://www.swift.org/swift-evolution/#?redirect-se=0401?

I can see in the init() inside https://www.swift.org/assets/javascripts/swift-evolution.js that we load proposals JSON from https://download.swift.org/swift-evolution/proposals.json. Is there an opportunity to do a redirect upon ?redirect-proposal=XXXX at that point?

alexandersandberg commented 1 year ago

I've just had a look inside the js for the proposals search screen at https://www.swift.org/swift-evolution. Could SE proposal code redirects be handled upon loading a dashboard URL like https://www.swift.org/swift-evolution/#?redirect-se=0401?

I can see in the init() inside https://www.swift.org/assets/javascripts/swift-evolution.js that we load proposals JSON from https://download.swift.org/swift-evolution/proposals.json. Is there an opportunity to do a redirect upon ?redirect-proposal=XXXX at that point?

It's a good idea! The problem with that is that the data is loaded dynamically on page load which can take a while if your internet connection is slow.

Instead of a client-side redirect like this, it would be ideal to have the redirects server-side. Then you would be redirected immediately to the proposal, without having to stop by Swift.org first.

alexhunsley commented 1 year ago

It's a good idea! The problem with that is that the data is loaded dynamically on page load which can take a while if your internet connection is slow.

Instead of a client-side redirect like this, it would be ideal to have the redirects server-side. Then you would be redirected immediately to the proposal, without having to stop by Swift.org first.

Good point, yeah!

dempseyatgithub commented 1 year ago

Yes, I think server-side redirects are the desired approach.

I think we should consider generating the redirects from the JSON provided by https://api.github.com/repos/apple/swift-evolution/contents/proposals.

At present I don’t know how often proposals.json is generated, but getting the values from GitHub directly would ensure we don’t have situations where the site and redirects are generated shortly before proposals.json is generated, leading to the site redirects being out of date for a period of time.

@alexhunsley I took a look at the script you have implemented on your GitHub pages page and that was cleverly done.

// @alexandersandberg