-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
56 lines (50 loc) · 2.02 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import re
# Global config for the whole build process
# Any of these you want to change you change before calling any build functions
main_folder = os.path.dirname( os.path.realpath( __file__ ) )
database_config_file = os.path.join( main_folder, 'database', 'database.yml' )
static_folder = os.path.join( main_folder, 'database', 'static' )
tasks_folder = os.path.join( main_folder, 'database', 'tasks' )
topics_folder = os.path.join( main_folder, 'database', 'topics' )
jekyll_input_folder = os.path.join( main_folder, 'jekyll-input' )
jekyll_imgs_folder = os.path.join( jekyll_input_folder, 'assets', 'dynamic-images' )
site_url = 'https://how-to-data.org/'
# How to make an absolute path relative to this project
# For example, if the project root is /example/path,
# then relativize_path("/example/path/foo/bar.html") == "foo/bar.html"
# and relativize_path("/not/same/path/at.all") == "/not/same/path/at.all"
def relativize_path ( input_path ):
prefix = main_folder
if prefix[-1] != os.path.sep:
prefix += os.path.sep
if input_path.startswith( prefix ):
return input_path[len(prefix):]
return input_path
# One site-wide global function:
# How to blogify a title of any resource into a filename (with lower case and hyphens).
def blogify ( title ):
return re.sub( '^-+|-+$', '', re.sub( '[^a-z0-9]+', '-', title.lower() ) )
# Link to a page in the site online; provide the permalink without the absolute URL,
# and this function prefixes the web site's URL and forms a hyperlink.
def site_link ( permalink ):
return f'{site_url}{permalink}/'
# Mapping from common file type descriptions to their extensions.
extension_for_type = {
'md' : 'md',
'markdown' : 'md',
'Markdown' : 'md',
'ipynb' : 'ipynb',
'notebook' : 'ipynb',
'Jupyter' : 'ipynb',
'Jupyter notebook' : 'ipynb',
'doc' : 'doc',
'docx' : 'docx',
'Word' : 'docx',
'Word doc' : 'docx',
'document' : 'docx',
'Word document' : 'docx',
'Rmd' : 'Rmd',
'RMarkdown' : 'Rmd',
'Rmarkdown' : 'Rmd'
}