-
Notifications
You must be signed in to change notification settings - Fork 1
/
pelicanconf.py
218 lines (163 loc) · 4.87 KB
/
pelicanconf.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
import os
import sys
from glob import glob
from pathlib import Path
import re
sys.path.append('.')
from myplugins import reader, replacements, mod_html, set_count, mod_content, category_meta
from myplugins.jinja_filters import JINJA_FILTERS
sys.path.append('.')
abspath = os.path.abspath(__file__)
cur_dir = os.path.dirname(abspath)
re_slnu = re.compile(r"/([0-9]+|[A-Z]{1,2})-")
class DynamicSetting(object):
def __init__(self, f):
self.f = f
def format(self, **metadata):
return self.f(metadata).format(**metadata)
def myglob(root, *args):
r = []
for a in args:
r.extend(glob(root+a))
return sorted(r)
def rcglob(root, *args):
ok = []
ko = []
root = Path(root)
for a in args:
if a.startswith("!"):
ko.extend(root.rglob("*."+a[1:]))
else:
for i in root.rglob("*."+a):
if i not in ko:
ok.append(i)
return sorted(ok)
AUTHOR = 's-nt-s'
SITENAME = 'Apuntes GSI'
SITEURL = 'https://s-nt-s.github.io/GSI'
GITHUB_URL = 'https://github.com/s-nt-s/GSI'
SOURCE_URL = GITHUB_URL+'/tree/master'
MAPA_URL = 'mapa'
SITEURL = os.environ.get('URL', SITEURL)
# LEN_CUR_DIR se usa para hacer relativas rutas como source_path
LEN_CUR_DIR = len(cur_dir)+1
# Uncomment following line if you want document-relative URLs when developing
RELATIVE_URLS = True
TIMEZONE = 'Europe/Madrid'
DEFAULT_LANG = 'es'
# Feed generation is usually not desired when developing
FEED_ALL_ATOM = None
CATEGORY_FEED_ATOM = None
TRANSLATION_FEED_ATOM = None
AUTHOR_FEED_ATOM = None
AUTHOR_FEED_RSS = None
DISPLAY_PAGES_ON_MENU = False
DISPLAY_CATEGORIES_ON_MENU = False
MENUITEMS = (
('About', 'about'),
('Mapa', MAPA_URL),
('Ver Github', SOURCE_URL),)
# Social widget
SOCIAL = (
('@s-nt-s', 'https://github.com/s-nt-s/'),
)
#DEFAULT_PAGINATION = 10
SUMMARY_MAX_LENGTH = 0
FEED_ALL_ATOM = 'feeds/all.atom.xml'
#FEED_ALL_RSS = 'feeds/all.rss.xml'
#AUTHOR_FEED_RSS = 'feeds/%s.rss.xml'
RSS_FEED_SUMMARY_ONLY = False
DEFAULT_DATE_FORMAT = '%Y-%m-%d'
# 'index',
DIRECT_TEMPLATES = ['sitemap', 'map']
AUTHOR_SAVE_AS = False
SITEMAP_SAVE_AS = 'sitemap.xml'
MAP_SAVE_AS = MAPA_URL + '/index.html'
PAGE_PATHS = ['pages']
ARTICLE_PATHS = ['posts']
def get_url(metadata):
path = metadata['path']
path = path.split(os.path.sep)
path = path[1:-1]
arr = []
if len(path) > 0:
path = os.path.join(*path)
arr.append(path)
isIndex = metadata['slug'] == 'index' or metadata.get('index') == True
if not isIndex:
arr.append("{slug}")
if not arr:
return "/"
url = "/".join(arr)
if isIndex:
return url + "/"
url = re_slnu.sub("/", url)
return url+".html"
def url_to_file(url):
url = url.rstrip("/")
if url:
if url.endswith(".html"):
return url
return url + "/index.html"
return "index.html"
@DynamicSetting
def ARTICLE_URL(metadata, *args, **kargv):
return get_url(metadata)
@DynamicSetting
def ARTICLE_SAVE_AS(metadata, *args, **kargv):
url = get_url(metadata)
return url_to_file(url)
@DynamicSetting
def PAGE_URL(metadata, *args, **kargv):
return get_url(metadata)
@DynamicSetting
def PAGE_SAVE_AS(metadata):
url = get_url(metadata)
return url_to_file(url)
ARTICLE_LANG_SAVE_AS = ARTICLE_SAVE_AS
ARTICLE_LANG_URL = ARTICLE_URL
#USE_FOLDER_AS_CATEGORY = True
#FILENAME_METADATA = '(?P<slug>.*)'
FILENAME_METADATA = '([^-]+-)?(?P<slug>.*)'
PATH_METADATA = '[^\/]+/(?P<category>[^/]+).*/([^-]+-)?(?P<slug>[^\.-]+)\.[^\.]+'
#PATH_METADATA = '[^\/]+/(?P<category>.*)/([^-]+-)?(?P<slug>[^\.-]+)\.[^\.]+'
ARTICLE_ORDER_BY = 'source_path'
PAGE_ORDER_BY = 'source_path'
CONTENT_FILES = []
CONTENT_MARKD = []
for path in PAGE_PATHS + ARTICLE_PATHS:
for f in rcglob("content/"+path, "*"):
if f.is_file():
fn = str(f).split("/", 1)[-1]
if f.suffix == ".md":
CONTENT_MARKD.append(fn)
else:
CONTENT_FILES.append(fn)
FAVICON_FILES = [i.split("/",1)[-1] for i in myglob("content/extra/favicon/*.",
"png",
"ico",
"svg",
"webmanifest",
"xml"
)]
STATIC_PATHS = [
'images',
'extra/robots.txt'
] + FAVICON_FILES + CONTENT_FILES
EXTRA_PATH_METADATA = {
'extra/robots.txt': {'path': 'robots.txt'},
'extra/favicon.ico': {'path': 'favicon.ico'}
}
for f in FAVICON_FILES:
EXTRA_PATH_METADATA[f] = {'path': os.path.basename(f)}
for f in CONTENT_FILES:
EXTRA_PATH_METADATA[f] = {'path': re_slnu.sub("/", f.split("/", 1)[-1])}
THEME = cur_dir + '/themes/notmyidea-custom'
THEME = cur_dir + '/themes/mini'
REPLACEMENTS_CONFIG = cur_dir + "/config/replacements.yml"
ABBR_CONFIG = cur_dir + "/config/abbr/"
PLUGINS = [reader, replacements, mod_content, mod_html, set_count, category_meta]
PUBLISH_ALL = True