Skip to content

Custom template for tutorial sections #3082

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

Merged
merged 1 commit into from
Aug 25, 2023
Merged

Custom template for tutorial sections #3082

merged 1 commit into from
Aug 25, 2023

Conversation

nelliemckesson
Copy link
Contributor

This PR scrapes the webpage for a given tutorial (e.g., https://www.raspberrypi.com/tutorials/build-your-own-weather-satellite-receiving-station/), and then creates a custom section in the documentation that sources in the tutorial description and header image.

Note that it is looking for these two meta elements on the linked page (attn: @mudge to let us know if this markup is prone to frequent changes):

<meta name="description" content="In this tutorial, we show you how to build a weather satellite receiving station using Raspberry Pi and a low-cost USB Software Defined Radio">
...
<meta property="og:image" content="https://www.raspberrypi.com/app/uploads/2023/08/Antenna-1024x576.jpg">

...though it should degrade gracefully, so if it can't find those it just won't show anything.

@aallan I laid it out card-style, so you should see something like the below, but let me know if you had something else in mind (the card is a clickable link):

Screen Shot 2023-08-24 at 9 39 35 AM

Required adoc markup is as follows:

[.tutoriallink, link=https://www.raspberrypi.com/tutorials/build-your-own-weather-satellite-receiving-station/]
==== Your Tutorial Heading

Your text content!

Someone else should definitely test this before we merge (by adding a tutorial section somewhere and then make serve_html), since I'm doing something a bit fancy and I'd love to be sure I'm not missing any key instructions or dependencies.

@nelliemckesson
Copy link
Contributor Author

(Oh yah, fixes #3060 )

@mudge
Copy link
Contributor

mudge commented Aug 24, 2023

If you want something more stable than scraping the HTML, I’m happy to provide a JSON API for this, e.g. https://www.raspberrypi.com/for-home/ currently uses https://www.raspberrypi.com/wp-json/rptl/v1/tutorials to show the 3 most recent tutorials.

@nelliemckesson
Copy link
Contributor Author

@mudge oh nice! More stable is definitely good, but I'll defer to your judgement here -- whatever you think is the best route to go.

@nelliemckesson
Copy link
Contributor Author

@mudge if we go the API route, we'll need a user-friendly way to select the correct record. For example, we'll need to set it up so folks like Al, Josh, etc., just need to include the tutorial url in their adoc files, and then we can get the corresponding tutorial record using just that url... does that make sense? And is it doable?

@mudge
Copy link
Contributor

mudge commented Aug 24, 2023

The markup should be stable (I can’t see us ditching the meta tags any time soon) so there’s no rush to change this to an API.

If we do go that route, we could parse the tutorial slug out of a URL and pass that to an API endpoint which would return just the information you need rather than the full HTML.

@nelliemckesson
Copy link
Contributor Author

@mudge ok cool, well since using an API creates more work for you, I'll let you decide if/when we switch over to that ;) If you feel inclined to make one, or if you find yourself tweaking the tutorial page markup, just ping me and I'll switch this handling over as well.

Copy link
Contributor

@aallan aallan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Thanks @nelliemckesson!

Agree that doing it the API way is going to be cleaner, but going to merge now and will open another issue to migrate to that when everyone has time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants