Skip to content

Commit fd457ab

Browse files
committed
v0.1.7: md metadata header, page nav, page footer
1 parent 0d5dd74 commit fd457ab

File tree

8 files changed

+59
-44
lines changed

8 files changed

+59
-44
lines changed

webifier/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = 'v0.1.6'
1+
__version__ = 'v0.1.7'

webifier/build/content.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import pathlib
3-
from .io_utils import read_file, data_name, prepend_baseurl
3+
from .io_utils import read_file, data_name, prepend_baseurl, read_yaml
4+
import yaml
45
from .jekyll import create_jekyll_file, create_jekyll_content_header, get_colab_url
56
from .notebook import generate_notebook_html
67
from .md import build_markdown
@@ -31,11 +32,26 @@ def process_content(builder, link, kind):
3132
metadata_path = link.get('metadata', os.path.join(content_dir, 'metadata.yml'))
3233
metadata_path = \
3334
f'{metadata_path}{"" if metadata_path.endswith(".yml") or metadata_path.endswith(".yaml") else ".yml"}'
35+
36+
metadata = None
37+
if kind == 'md':
38+
raw_str = read_file(filename)
39+
lines = raw_str.splitlines()
40+
if lines[0] == '---':
41+
try:
42+
idx = lines.index('---', 1)
43+
metadata = yaml.full_load('\n'.join(lines[1:idx]))
44+
raw_str = '\n'.join(lines[idx + 1:])
45+
except ValueError:
46+
pass
47+
content_str = build_markdown(builder=builder, raw=raw_str,
48+
assets_target_dir=builder.assets_dir)
3449
if os.path.isfile(metadata_path):
35-
metadata = builder.build_index(
50+
file_metadata = builder.build_index(
3651
index_file=metadata_path.replace(".ipynb" if kind == "notebook" else ".md", ''),
3752
assets_src_dir=content_dir, assets_target_dir=builder.assets_dir, index_type='content',
3853
search_slug=jekyll_target_file)
54+
metadata = file_metadata if metadata is None else {**metadata, **file_metadata}
3955
metadata_path = data_name(index_file=metadata_path.replace(".ipynb" if kind == "notebook" else ".md", ''),
4056
index_type='content')
4157
if 'text' not in link:
@@ -47,19 +63,24 @@ def process_content(builder, link, kind):
4763
link['description'] = metadata['header']['description']
4864

4965
else:
50-
metadata = dict(search=builder.config['search'])
51-
metadata_path = None
66+
metadata_path = None if metadata is None else data_name(index_file=metadata_path.replace(
67+
".ipynb" if kind == "notebook" else ".md", ''), index_type='content')
68+
metadata = dict(search=builder.config['search']) if metadata is None else builder.build_index(
69+
index=metadata, target_data_file=metadata_path.replace(".ipynb" if kind == "notebook" else ".md", ''),
70+
assets_src_dir=content_dir, assets_target_dir=builder.assets_dir, index_type='content',
71+
search_slug=jekyll_target_file, search_links=None, search_content=None)
5272

5373
link['kind'] = metadata.get('kind', kind.capitalize()) if 'kind' not in link else link['kind']
5474

5575
builder.checked_content[filename] = link
56-
content_str = generate_notebook_html(
57-
builder=builder,
58-
src=filename,
59-
assets_dir=builder.assets_dir, # where to move notebook assets
60-
search_links=metadata['search']['links']
61-
) if kind == 'notebook' else build_markdown(builder=builder, raw=read_file(filename),
62-
assets_target_dir=builder.assets_dir)
76+
if kind == 'notebook':
77+
content_str = generate_notebook_html(
78+
builder=builder,
79+
src=filename,
80+
assets_dir=builder.assets_dir, # where to move notebook assets
81+
search_links=metadata['search']['links']
82+
)
83+
6384
if metadata['search']['content']:
6485
builder.add_search_content(
6586
jekyll_target_file, content=content_str, title=link.get('text', kind.capitalize()),

webifier/build/io_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,18 @@ def wrapper(self, *args, **kwargs):
158158
return wrapper
159159

160160

161-
def mix_folders(root_src_dir, root_target_dir):
161+
def mix_folders(root_src_dir, root_target_dir, file_map=None):
162162
if root_src_dir == root_target_dir:
163163
return
164164
for src_dir, dirs, files in os.walk(root_src_dir):
165165
dst_dir = src_dir.replace(root_src_dir, root_target_dir, 1)
166+
if file_map and root_src_dir != src_dir and os.path.split(src_dir)[1] not in file_map:
167+
continue
166168
if not os.path.exists(dst_dir):
167169
os.makedirs(dst_dir)
168170
for file_ in files:
171+
if file_map and root_src_dir == src_dir and os.path.split(file_)[1] not in file_map:
172+
continue
169173
src_file = os.path.join(src_dir, file_)
170174
dst_file = os.path.join(dst_dir, file_)
171175
if not os.path.exists(dst_file):

webifier/jekyll/_includes/footer.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
class="bg-light p-3 m-auto text-center"
2020
{% endif %}
2121
>
22-
{% if site.data.index.footer.first %}
23-
{{ site.data.index.footer.text }}
24-
{% else %}
25-
{{ site.data.index.footer }}
26-
{% endif %}
22+
{{ include.footer.text | default: include.footer | default: site.data.index.footer.text | default: site.data.index.footer }}
2723
© Powered by <a class="link-primary" href="https://github.com/webifier/build">Webifier</a>
2824
</div>
2925
</footer>

webifier/jekyll/_includes/nav.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{% assign colab = include.colab %}
2-
{% if site.data.index.nav.fixed != null or site.data.index.nav.brand != null %}
3-
{% assign links = site.data.index.nav.content %}
2+
{% if include.nav.fixed != null or include.nav.brand != null or site.data.index.nav.fixed != null or site.data.index.nav.brand != null %}
3+
{% assign links = include.nav.content | default: site.data.index.nav.content %}
44
{% else %}
5-
{% assign links = site.data.index.nav %}
5+
{% assign links = include.nav.content | default: site.data.index.nav.content | default: site.data.index.nav %}
66
{% endif %}
77
<nav class="px-2 navbar navbar-expand-lg navbar-light bg-light m-0 p-2 sticky-top shadow">
88
{% if site.data.index.nav.brand %}

webifier/jekyll/_layouts/content.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
{% assign page_title = metadata.header.title | default: metadata.title %}
2525
{% include header.html background=metadata.header.background title=page_title
2626
description=metadata.header.description %}
27-
{% include nav.html colab=page.colab %}
27+
{% include nav.html colab=page.colab nav=metadata.nav %}
2828
<div class="container-fluid bg-white shadow app-body {% unless page.colab %}px-5 p-4{% endunless %}">
2929
{{ content }}
3030
</div>
3131
<div class="container-fluid bg-white shadow app-body">
3232

3333
{% include toc.html index=metadata level=1 %}
3434
</div>
35-
{% include footer.html background=metadata.footer.background %}
35+
{% include footer.html background=metadata.footer.background footer=metadata.footer %}
3636
</div>
3737
</body>
3838
</html>

webifier/jekyll/assets/css/main.css

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
21
body {
3-
zoom: 130%;
2+
zoom: 125%;
43
}
54

65
* > p:last-child { margin-bottom: 0 !important; }
76

87
a { text-decoration: none; }
98

10-
@keyframes gradient {
11-
0% {
12-
background-position: 0% 50%;
13-
}
14-
50% {
15-
background-position: 100% 50%;
16-
}
17-
100% {
18-
background-position: 0% 50%;
19-
}
20-
}
219
.hover-shadow:hover {
2210
filter: drop-shadow(0 0.1rem 0.3rem rgba(0,0,0, 0.5));
2311
}
@@ -36,10 +24,7 @@ footer {
3624

3725
.app-content {
3826
padding: 3vh 0;
39-
max-width:80%;
40-
}
41-
42-
.app-body {
27+
max-width:85%;
4328
}
4429

4530
.accordion-button:not(.collapsed) {
@@ -61,7 +46,13 @@ footer {
6146
background-color: white;
6247
}
6348

64-
@media only screen and (max-width: 1300px) {
49+
@media only screen and (max-width: 1400px) {
50+
.app-content {
51+
max-width:95%;
52+
}
53+
}
54+
55+
@media only screen and (max-width: 1200px) {
6556
.app-content {
6657
max-width:100%;
6758
}

webifier/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
TARGET_INDEX_FILE = 'index.yml'
1010
DEFAULT_TEMPLATES_DIR = "."
1111

12+
1213
def main():
1314
parser = argparse.ArgumentParser(
1415
description=f'''
@@ -25,12 +26,14 @@ def main():
2526
parser.add_argument('--output',
2627
dest='output', help='build target directory (default: "webified")', default=DEFAULT_OUTPUT_DIR)
2728
parser.add_argument('--templates-dir',
28-
dest='templates_dir', help='templates base directory (default: ".")', default=DEFAULT_TEMPLATES_DIR)
29+
dest='templates_dir', help='templates base directory (default: ".")',
30+
default=DEFAULT_TEMPLATES_DIR)
2931
args = parser.parse_args()
3032

31-
print(f'baseurl: {args.base_url}, repo_full_name: {args.repo_full_name}')
33+
print(f'webifier: {__version__}, baseurl: {args.base_url}, repo_full_name: {args.repo_full_name}')
3234

33-
mix_folders(root_src_dir='.', root_target_dir=args.output) # todo: get file map
35+
mix_folders(root_src_dir='.', root_target_dir=args.output,
36+
file_map=['favicon.ico', '_includes', '_layouts', 'assets', 'search.json']) # todo: improve file map
3437
mix_folders(root_src_dir=os.path.join(os.path.join(*os.path.split(__file__)[:-1], 'jekyll')),
3538
root_target_dir=args.output)
3639
builder = Builder(base_url=args.base_url, repo_full_name=args.repo_full_name, output_dir=args.output,

0 commit comments

Comments
 (0)