Он определенно может быть легко интегрирован в Sphinx-Documentation.
Я подал заявку на учетную запись и получил ключи API.
Чтение: https://community.algolia.com/docsearch/run-your-own.html
Я установил бесплатную docsearch-scraper
из github под Python 2.7 и MacOS 10.13 изаставить его работать с помощью pipenv и дополнительной пост-установки отсутствующего модуля dotenv.
После некоторой путаницы я использовал самонастраиваемый config.json
, основанный на выводе команды ./docsearch bootstrap
, заменяя все вхождения "FIXME" в строках, начинающихся с "lvln", на ".section" и заменяя "FIXME "в строке, начинающейся с" text "с" .document "(см. Пример ниже).
Мы успешно проиндексировали Sphinx-Documentation и, запустив команду .docsearch playground
, открыли тестовый веб-сервер, который сразу же дал отличные результаты.
Мы используем readthedocs sphinx_rtd_theme
, и вы можете легко добавлять фрагменты CSS-Links и Javascript из документов algolia в файл расширения шаблона page.html
, созданный в папку _source/_templates/
(см. Ниже).Эта папка может быть необходима для регистрации в conf.py
вашей настройки!
Добавьте это к вашему conf.py
в существующей позиции:
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
и
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
Я могу вернуться сюда с более подробным пошаговым руководством, когда я закончу интеграцию.
пример config.json:
{
"index_name": "yourindexname",
"start_urls": [
"https://replaceme.com"
],
"stop_urls": [
"https://replaceme.com/omit"
],
"selectors": {
"lvl0": ".section h1",
"lvl1": ".section h2",
"lvl2": ".section h3",
"lvl3": ".section h4",
"lvl4": ".section h5",
"lvl5": ".section h6",
"text": ".document p, .document li"
},
}
подробнее в: https://community.algolia.com/docsearch/config-file.html
Это добавляет CSS-файл algolia и файл custom.css
в папку _source/_static/
для переопределения стилей.Источник фрагментов см. https://community.algolia.com/docsearch/dropdown.html
пример page.html
шаблон:
{% extends "!page.html" %}
{% set css_files = css_files + ["https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css", "_static/custom.css"] %}
{% block footer %}
<script
src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
<script>
docsearch({
// Your apiKey and indexName will be given to you once
// we create your config. The appId value is missing in the first
// version of this example and in the algolia community doc
// until today (5th march of 2019).
appId: '<your-app-id>',
apiKey: '<yourkey>',
indexName: '<yourindex>',
// Replace inputSelector with a CSS selector
// matching your search input
inputSelector: '#rtd-search-form input[type=text]',
// Set debug to true if you want to inspect the dropdown
debug: true
});
</script>
{% endblock %}
ToDo: Проверка ссылок на документацию сообщества algolia
Тип: Вы можете проверить, еслиСелектор ввода работает путем добавления этого стиля в ваш файл custom.css
:
#rtd-search-form input[type=text]{
background-color: #c51919; /* red */
}