API docs - offline usage

Hi,
I downloaded crystal-1.5.0-docs.tar.gz from the github release page for offline usage.
The html links work very well, but the search field doesn’t work at all.

Is it possible to get this working as well?

Thanks in advance.

1 Like

Search should work offline as well (when opened as a local file instead of served via HTTP).
It works for me. Tested in Firefox and Chromium-based browsers.

What browser are you using? Are there any error messages in the console?

Yes, you are right. I forgot to mention that the browser (Firefox 102.0) runs in a docker container. The Firefox web-developer-tools console says “CrystalDocs search index not initialized, delaying search” if I type something info the field …

It works for me, I open API document from my favorite like this: file:///home/zw963/Crystal/docs/index.html in Firefox, it can search keyword successful, when click on source code, it jump to the file in github with current release version.

Sorry, it was my mistake.
If you really really want to use the docs offline, you have to replace all https-URLs of all HTML-files with local file-URLs. Therefore I did the following:

> find crystal-docs/ -name "*.html" -exec sed -i 's@https://github.com/crystal-lang/crystal/blob/.*/src@file:///usr/share/crystal/src@g' {} \;

This is necessary in order to have valid links to local (offline) sourcecode files.
The search field now is working as expected.
First I replaced completely all files. But if you replace also the URLs in search-index.js the search is broken!
Unfortunately too little Javascript know-how …

If you do like this, you have to handle the jump to the specified line in your’s editor?

e.g. #L287 of following url.

will be replace to

file:///usr/share/crystal/src/string_scanner.cr#L287

How you jump to the line 287 ?

Indeed, jump to a line doesn’t work.
I know about this, but found no solution until now … it seems to be a Github feature …

You can try replace #L to :,

e.g.

file:///usr/share/crystal/src/string_scanner.cr#L287

convert to

file:///usr/share/crystal/src/string_scanner.cr:287

Then change system to use your’s editor open it, most of editor probably support this.