Skip to content

POC: Feature random code snippet on landing page #303

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

Conversation

alexandersandberg
Copy link
Member

@alexandersandberg alexandersandberg commented May 13, 2023

Adds proof of concept for dynamic code snippet on the landing page.

Motivation:

This is a proof of concept for featuring a random code snippet on the landing page. Whether we want to add dynamic content to the landing page or not is a separate discussion, but with this, we can preview what it would be like.

Modifications:

The snippets are stored in _data/featured_snippets.yml. For this POC, I used some random snippets from TSPL. If/when implementing this, we would use some better, more representative snippets.

I now render all snippets in the HTML and hide them all except for the first one with CSS. This allows the syntax highlighter to find and highlight all snippets. I found this to be the best and easier way of doing this. Other possible ways might involve preprocessing the data file to add syntax highlighting instead.

If JavaScript is disabled, only the first snippet in the data file will be shown.

If JavaScript is enabled, there's a script that will randomly move the visible class to one of the `featured snippets every time the page loads.

Keep in mind that the placing of this code snippet is not final. This is just an example of where/how it can be included on the landing page.

Note: I also included a fix for the inconsistent sizing of the latest release button.

Result:

Preview link: https://alexandersandberg-swift-org-website.netlify.app

CleanShot 2023-05-13 at 16 45 38

Let me know if you have a better idea of how to accomplish this while keeping the syntax highlighting.

@dempseyatgithub
Copy link
Contributor

This is very nice - and without adding a great deal of complexity to the site.

In terms of placement on the page, I think the code snippet should be above “Why Swift?” and probably above the three main buttons.

The code snippet seems like it would be more like the product photo ‘hero image' at the top of a product page, as opposed to fitting in the flow of the rest of the page content.

Maybe that opening paragraph "Swift is a general-purpose programming language…” ends up side by side with a narrower code box?

It would be similar to the layout in Reda’s next-gen design prototype.

@alexandersandberg
Copy link
Member Author

This is very nice - and without adding a great deal of complexity to the site.

In terms of placement on the page, I think the code snippet should be above “Why Swift?” and probably above the three main buttons.

The code snippet seems like it would be more like the product photo ‘hero image' at the top of a product page, as opposed to fitting in the flow of the rest of the page content.

Maybe that opening paragraph "Swift is a general-purpose programming language…” ends up side by side with a narrower code box?

It would be similar to the layout in Reda’s next-gen design prototype.

Thanks for the feedback! I definitely agree that the placement of this can be improved. I think it would be nice to get the actual snippets we will use from @TimTr's team to play with for that, as they may or may not require some additional text/explanation.

@tomerd
Copy link
Contributor

tomerd commented May 16, 2023

love it!

Copy link
Member

@kaishin kaishin left a comment

Choose a reason for hiding this comment

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

Really good idea and even better implementation!

@alexandersandberg
Copy link
Member Author

I pushed a few changes:

  • Moved the snippet to the top, under the tagline.
  • I added a fixed height to the snippet to prevent layout shifts on reload. We can revisit this in the bigger content improvements PR once we have to actual code snippets we want to use to see which height makes the most sense.
  • Removed a long snippet example — we should not feature longer snippets like that anyway

I will merge this now, but we should remember to add the following TODOs in the main PR:

  • Replace snippet placeholders in _data/featured_snippets.yml with actual snippets we want to feature (cc: @TimTr)
  • Possibly adjust the current 15rem height of the featured snippet to better fit our final snippets

@alexandersandberg alexandersandberg merged commit 56b7810 into swiftlang:content-improvements Jun 22, 2023
@alexandersandberg alexandersandberg deleted the alexander/content-improvements branch June 22, 2023 06:31
kaishin added a commit that referenced this pull request Sep 7, 2023
* Update landing page content (#127)
* First pass at the new Getting Started page (#174)
* Adding Getting Started tutorial for SwiftUI / iOS 16. (#185)
* Add data file with items for "Go Further" section (#184)
* Add cli and library getting started guides (#192)
* Getting started tweaks (#208)
* Rename Markdown files to have an `.md` extension. (#209)
* Fix typo (#214)
* Update getting started page layout (#204)
* Add documentation information to Getting Started (#226)
* Add Vapor Getting Started guide (#229)
* Update content-improvments branch per feedback (#244)
* Tweak SwiftUI tutorial (#240)
* Add TSPL Go Further section and resource thumbnails (#227)
* Improve 'Why Swift?' section on landing page (#252)
* Replace Go Further item for advanced String Under The Hood blog post with item for Structures and Classes chapter in TSPL (#254)
* Update landing page layout (#267)
* Link to developer.apple.com from apple use case (#291)
* Smaller landing page changes on content improvements branch (#294)
* Update Go Further section (#300)
* Update icons and placeholder image (#301)
* Improve description of use cases and getting started guides (#304)
* POC: Feature random code snippet on landing page (#303)
* New “Swift is…” and About page copy (#336)
* Move link to A Swift Tour to the Use Cases section (#329)
* Add consistent download section to start and end of each guide (#351)
* Add a new install page, update the download page, and move release yml files into one file. (#310)
* Update navigation for install page (#355)
* Update cli and library getting started guides (#357)
* Content improvement guide updates (#373)
* Add value and reference types article (#377)
* Add some showcase snippets (#371)
* Resolve issue with Red Hat download links (#379)
* Add Info about Scoop for Windows install page (#382)

---------

Co-authored-by: Alexander Sandberg <[email protected]>
Co-authored-by: Paul Hudson <[email protected]>
Co-authored-by: James Dempsey <[email protected]>
Co-authored-by: tomer doron <[email protected]>
Co-authored-by: Dave Verwer <[email protected]>
Co-authored-by: Tim Condon <[email protected]>
Co-authored-by: Max Desiatov <[email protected]>
Co-authored-by: Mishal Shah <[email protected]>
Co-authored-by: AG <[email protected]>
Co-authored-by: Ted Kremenek <[email protected]>
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.

4 participants