-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
138 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1487,7 +1487,10 @@ you can't, this will work. | |
Configuration | ||
------------- | ||
|
||
The configuration file is called ``conf.py`` and can be used to customize a lot of | ||
You can pass a configuration file to ``nikola`` by using the ``--conf`` command line switch. | ||
Otherwise the ``conf.py`` file in the root of the Nikola website will be used. | ||
|
||
The configuration file can be used to customize a lot of | ||
what Nikola does. Its syntax is python, but if you don't know the language, it | ||
still should not be terribly hard to grasp. | ||
|
||
|
@@ -1511,10 +1514,33 @@ them. For those options, two types of values can be provided: | |
* a string, which will be used for all languages | ||
* a dict of language-value pairs, to have different values in each language | ||
|
||
.. note:: It is possible to load the configuration from another file by specifying | ||
``--conf=path/to/other.file`` on Nikola's command line. For example, to | ||
build your blog using the configuration file ``configurations/test.conf.py``, | ||
you have to execute ``nikola build --conf=configurations/test.conf.py``. | ||
.. note:: | ||
As of version 8.0.3 it is possible to create configuration files which inherit values from other Python files. | ||
This might be useful if you're working with similar environments. | ||
|
||
Example: | ||
conf.py: | ||
.. code:: python | ||
BLOG_AUTHOR = "Your Name" | ||
BLOG_TITLE = "Demo Site" | ||
SITE_URL = "https://yourname.github.io/demo-site | ||
BLOG_EMAIL = "[email protected]" | ||
BLOG_DESCRIPTION = "This is a demo site for Nikola." | ||
debug.conf.py: | ||
.. code:: python | ||
import conf | ||
globals().update(vars(conf)) | ||
SITE_URL = "http://localhost:8000/" | ||
or | ||
|
||
.. code:: python | ||
from conf import * | ||
SITE_URL = "http://localhost:8000/" | ||
Customizing Your Site | ||
--------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
|
||
import os | ||
import fnmatch | ||
import subprocess | ||
|
||
DOIT_CONFIG = { | ||
'default_tasks': ['flake8', 'test'], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
import time | ||
|
||
BLOG_AUTHOR = "Your Name" | ||
BLOG_TITLE = "Demo Site" | ||
SITE_URL = "https://example.com/" | ||
BLOG_EMAIL = "[email protected]" | ||
BLOG_DESCRIPTION = "This is a demo site for Nikola." | ||
DEFAULT_LANG = "en" | ||
CATEGORY_ALLOW_HIERARCHIES = False | ||
CATEGORY_OUTPUT_FLAT_HIERARCHY = False | ||
HIDDEN_CATEGORIES = [] | ||
HIDDEN_AUTHORS = ['Guest'] | ||
LICENSE = "" | ||
|
||
CONTENT_FOOTER_FORMATS = { | ||
DEFAULT_LANG: ( | ||
(), | ||
{ | ||
"email": BLOG_EMAIL, | ||
"author": BLOG_AUTHOR, | ||
"date": time.gmtime().tm_year, | ||
"license": LICENSE | ||
} | ||
) | ||
} | ||
|
||
ADDITIONAL_METADATA = { | ||
"ID": "conf" | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/data/test_config/config.with+illegal(module)name.characters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import conf | ||
|
||
globals().update(vars(conf)) | ||
ADDITIONAL_METADATA = { | ||
"ID": "illegal" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import conf | ||
|
||
globals().update(vars(conf)) | ||
ADDITIONAL_METADATA = { | ||
"ID": "prod" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import re | ||
|
||
from nikola import __main__ as nikola | ||
|
||
from .base import BaseTestCase | ||
|
||
|
||
class ConfigTest(BaseTestCase): | ||
"""Provides tests for the configuration-file handling.""" | ||
@classmethod | ||
def setUpClass(self): | ||
self.metadata_option = "ADDITIONAL_METADATA" | ||
script_root = os.path.dirname(__file__) | ||
test_dir = os.path.join(script_root, "data", "test_config") | ||
nikola.main(["--conf=" + os.path.join(test_dir, "conf.py")]) | ||
self.simple_config = nikola.config | ||
nikola.main(["--conf=" + os.path.join(test_dir, "prod.py")]) | ||
self.complex_config = nikola.config | ||
nikola.main(["--conf=" + os.path.join(test_dir, "config.with+illegal(module)name.characters.py")]) | ||
self.complex_filename_config = nikola.config | ||
self.check_base_equality(self.complex_filename_config) | ||
|
||
@classmethod | ||
def check_base_equality(self, config): | ||
"""Check whether the specified `config` equals the base config.""" | ||
for option in self.simple_config.keys(): | ||
if re.match("^[A-Z]+(_[A-Z]+)*$", option) and option != self.metadata_option: | ||
assert self.simple_config[option] == self.complex_config[option] | ||
|
||
def test_simple_config(self): | ||
"""Check whether configuration-files without ineritance are interpreted correctly.""" | ||
assert self.simple_config[self.metadata_option]["ID"] == "conf" | ||
|
||
def test_inherited_config(self): | ||
"""Check whether configuration-files with ineritance are interpreted correctly.""" | ||
self.check_base_equality(config=self.complex_config) | ||
assert self.complex_config[self.metadata_option]["ID"] == "prod" | ||
|
||
def test_config_with_illegal_filename(self): | ||
"""Check whether files with illegal module-name characters can be set as config-files, too.""" | ||
self.check_base_equality(config=self.complex_filename_config) | ||
assert self.complex_filename_config[self.metadata_option]["ID"] == "illegal" |