Mocking Default Landing Page

Mocking Default Landing Page

In this example, we'll construct the landing page that you can see at https://docs.developerhub.io . Our landing page is auto-generated, which means that it automatically updates whenever the contents of the docs are changed. The page consists of a "hero", which we won't go through since it's basic HTML, and then the autogenerated part.

In the auto-generated part, we should a card for every category in our Support Center documentation section. Every cards lists 3 pages and a Show All button.

1HTML

The HTML for the landing page is very simple. All it is shown is a heading and then a div with id landing-cards in which we will generate the cards.

2Listening to "oncardschanged"

To show the cards, we can listen to an event called oncardschanged. This event is dispatched when the reader navigates to the landing page. The event details contain the information needed to generate the layout.

3Checking if we're on a landing page

Check if we're on a landing page as opposed to a custom page. (You could also implement the same thing on a custom page if needed)

4Generating cards

event.detail.docs is an array of objects representing the available card grouping strategy. Each object (variable card here) has a title and a link. This represents a category in our documentation. We'll create a card of each one of them, then create an H4 which will contain the link to the title.

5Generate links

Each object also has details, which again is an array of objects containing titles and links. This represents a page in our documentation. We'll create a link for each object and place it in the card.

6Finalising the UI

The rest of the code is using bootstrap classes to make two nice columns and adding the cards to them. There is a "Show All" button which takes the main link of the card.

7Setting up Links

The last function window.applyClickHandlersOnLinks() tells the renderer to make the links that were just added using javascript into single page application links. Without this call, clicking on a link makes the whole page refresh. Always remember to call it after all links are added.

HTML
Custom HEAD Tags
Copy
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard
  Last updated by Zaid Daba'een