LoginSignup
2
1

More than 5 years have passed since last update.

SphinxのサイドバーでIEのみディレクトリが開いてしまう時の対処

Posted at

現象

  • sphinx_rtd_themeを使っている時に、サイドバーの折りたたみの親を開こうとすると、ディレクトリ一覧が表示される
  • ApacheでIndexesを削除すると、403エラーになってしまう

原因

  • Sphinxが出力するtoctreeのHTMLで、選択中のものはaタグのhref属性が空文字列("")であるため
  • FirefoxやChromeは空文字列だと、カレントページを開くが、IEはなぜか親ディレクトリを開きに行く

対処

Sphinx自体を修正するのが筋な気もするけど、影響範囲が測りきれなくてJavaScriptで対応。
hrefが空文字列だったら、#に書き換える。

conf.py
def setup(app):
    app.add_javascript('custom.js')
custom.js
$(function() {
  $('a[href=""]').attr('href', '#');
});
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1