Giter Club home page Giter Club logo

Comments (5)

mattt avatar mattt commented on June 18, 2024

Related to #44

from swift-doc.

kean avatar kean commented on June 18, 2024

I'm using lunr.js on https://kean.blog/nuke/guides/welcome and can build something similar for swift-doc. I built it using plain JS without any dependencies.

from swift-doc.

kean avatar kean commented on June 18, 2024

@mattt, do you have any preferences in terms of the implementation or design? I'm not entirely sure where to add it. I have a couple of options in mind (these are just mockups).

Features

  • Search on the site
  • And search on the page (?)
  • Keyboard navigation
  • Start searching by pressing f
  • Generated index should be served as a plain json file so that it could be used on other websites (use-case: cross-site search from https://kean.blog/nuke/guides/welcome)

Input Position

Option 1

Add it to a header and (optionally) make the header fixed.

Screen Shot 2021-04-10 at 10 01 47

Option 2

Add it to the contents. I think this one looks nice, but there are a couple of potential issues.

Cons:

  • It can give the wrong impression that it search on the current page instead of the site. To mitigate it, we can do both and provide two sections with search results: "On this page" and "On the site."
  • Keyboard navigation. If the user presses f for search, we will have to scroll (?) to the top of the page. Not the end of the world.

Screen Shot 2021-04-10 at 10 03 05

Option 3

It could also go somewhere above the ToC.

Pros: looks nice and is always visible without messing with the header size.

Screen Shot 2021-04-10 at 10 10 07

Search Results

I think it would be nice if the search results would simply appear on the page using the same design as currently used for the main content. (Highlighting a selected item for programmatic navigation).

Screen Shot 2021-04-10 at 10 23 56

from swift-doc.

Lukas-Stuehrk avatar Lukas-Stuehrk commented on June 18, 2024

To collect additional data and to get an idea what is expected and familiar for users, I did a short benchmark (see details below). Search bar in the header seems to be the most used pattern by now used in developer documentations.

And I completely agree with your reasoning, @kean. I think you described the pros and cons of the different approaches really well. Option 2 definitely looks like it searches on the current page only. Personally, I like the visuals of Option 3 with the search in the side bar the most. But there I also see the problem that users could think that it only searches for the current page, especially because it's very close to the "on this page" element.

Benchmark details

Stripe has the search bar in the header.
Screenshot 2021-04-13 at 20 33 49

Apple has a super small search icon in the header which expands to a search bar
Screenshot 2021-04-13 at 20 34 23

Github has the search bar in the header
Screenshot 2021-04-13 at 20 37 26

React has the search bar in the header
Screenshot 2021-04-13 at 20 38 42

Twilio has a search bar with rather bad contrast in the header
Screenshot 2021-04-13 at 20 41 11

from swift-doc.

kean avatar kean commented on June 18, 2024

Thanks, @Lukas-Stuehrk. I also think the header is the most reasonable choice. Just to add to your list:

  • Microsoft – search in the header and they don't even worry about fixing it, which I think makes sense for an API Reference where pages are not too long
  • Google – also header, this time fixed. swift-doc doesn't really have a header currently.

As for the search results, maybe it's best not to re-invent the wheel and add a dropdown with search results. I can come up with something basic and it can be improved later if needed.

from swift-doc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.