Searching MDN on the Command Line

The Mozilla Developer Network recently switched its infrastructure. Now, the MDN content is stored in a Github repository in the form of HTML files with YAML front matter.

You can think of it, what you want, given their recent change in staffing MDN. But this repository opens up a new possibility to search the MDN content.

I traditionally struggle to find what I need with MDN‘s own search. Usually, if I search CSS properties, SVG attributes come first. If I look for JavaScript globals, some internal Firefox API methods are shown down the whole results page. But now, with the whole content only a

git clone https://github.com/mdn/content.git

away, I can employ other, more sophisticated tools to that task.

My favorite grep replacement, ack, together with ls and find, will help me cut to my desired information more quickly:

# find pages with the title "align-content"
$ ack ^title:.*align-content

# find mentions of @media and "pixel-ratio"
$ ack '@media.*pixel-ratio'

# get all global objects in Javascript
$ ls files/en-us/web/javascript/reference/global_objects/

# find all files regarding the HTMLImageElement:
$ find -ipath '**htmlimageelement**'

If that should somehow not be enough, you are now able to build your own custom web frontend (with search) ontop of those files.