2014-05-04 6 views
25

मैं कस्टम सीएसएस फ़ाइल कैसे जोड़ सकता हूं? निम्नलिखित config मेरे लिए काम नहीं करता है:स्फिंक्स में कस्टम सीएसएस फ़ाइल कैसे जोड़ें?

# conf.py 
html_static_path = ['_static'] 
html_theme = 'default' 
html_theme_options = { 
    'cssfiles': ['_static/style.css'] 
} 

परिणाम:

C:\temp\test-docs\docs>make html 
Running Sphinx v1.2.2 
loading pickled environment... not yet created 
building [html]: targets for 2 source files that are out of date 
updating environment: 2 added, 0 changed, 0 removed 
reading sources... [ 50%] help 
reading sources... [100%] index 

looking for now-outdated files... none found 
pickling environment... done 
checking consistency... done 
preparing documents... 
Theme error: 
unsupported theme option 'cssfiles' given 

उत्तर

29

एक आसान तरीका अपने conf.py में जोड़ने के लिए है:।

def setup(app): 
    app.add_stylesheet('css/custom.css') # may also be an URL 

फिर फ़ाइल को _static/css/ फ़ोल्डर में डालें।

+2

धन्यवाद - यह स्वीकार्य उत्तर होना चाहिए! –

+1

'app.add_javascript ('file.js') के माध्यम से जावास्क्रिप्ट फ़ाइलों को जोड़ें। – Anil

+2

हम्म यह मेरे लिए काम नहीं कर रहा प्रतीत होता है –

20

आप डिफ़ॉल्ट स्फिंक्स विषय का विस्तार करके कस्टम सीएसएस शामिल करने के लिए सक्षम होना चाहिए। आपके conf.py में आप निर्दिष्ट करेंगे कि थीम का आपका एक्सटेंशन कहां होगा, जैसे कि।

# Add any paths that contain templates here, relative to this directory. 
templates_path = ['_templates'] 

फिर _templates में आप 'layout.html' है कि इस तरह के रूप में अपने cssfiles शामिल होंगे नामित डिफ़ॉल्ट थीम के लिए एक एक्सटेंशन बनाने जाएगा।

{# layout.html #} 
{# Import the theme's layout. #} 
{% extends "!layout.html" %} 

{% set css_files = css_files + ['_static/style.css'] %} 

अधिक जानकारी के लिए templating पर स्फिंक्स के दस्तावेज़ देखें।

+0

क्या आप समझा सकते हैं, प्रतीक '!' का अर्थ क्या है? – ole

+2

"विस्मयादिबोधक टेम्पलेट के नाम को विस्मयादिबोधक चिह्न के साथ उपसर्ग करके, स्फिंक्स अंतर्निहित HTML थीम से लेआउट टेम्पलेट लोड करेगा।" मैंने ऊपर templating पर स्फिंक्स दस्तावेज के लिए एक लिंक जोड़ा है। मुख्य रूप से उस पंक्ति को डिफ़ॉल्ट स्फिंक्स layout.html, या जो भी विषय आपने स्थापित किया हो, को विस्तारित करने के लिए कहा जाता है। – Cole

+1

Thx, एक और सवाल plz: उदाहरण के लिए उदाहरण के रूप में आप 'html बनाते हैं' के रूप में काम करते हैं, लेकिन डिफ़ॉल्ट थीम (sphinx_rtd_theme) के साथ [readthedocs.org] (http://readthedocs.org) पर काम नहीं करते हैं। – ole

8

विकल्प जिन्हें आप html_theme_options के माध्यम से कॉन्फ़िगर कर सकते हैं थीम-निर्भर हैं। क्या उपलब्ध है यह जानने के लिए अपने विषय के theme.conf के [options] अनुभाग देखें।

एक वैश्विक आधार पर है, हालांकि, आप html_context अपने conf.py में css_files की सेटिंग को ओवरराइड करने के लिए (भी और, उस बात के लिए script_files) को परिभाषित कर सकते हैं:

html_context = { 
    'css_files': ['_static/custom.css'], 
} 

(संदर्भ के लिए, पर एक नजर है स्फिंक्स का builders.html.StandaloneHTMLBuilder.prepare_writing() और how self.globalcontext gets populated there देखें)

+0

धन्यवाद! दिए गए उत्तरों में से, यही कारण है कि मुझे basic.css में कष्टप्रद ऑटो-हाइफेनेशन को ओवरराइड करने में मदद मिली। – tterry

संबंधित मुद्दे