Skip to content

Commit

Permalink
v0.1.7: md metadata header, page nav, page footer
Browse files Browse the repository at this point in the history
  • Loading branch information
vahidzee committed Oct 9, 2021
1 parent 0d5dd74 commit fd457ab
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 44 deletions.
2 changes: 1 addition & 1 deletion webifier/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = 'v0.1.6'
__version__ = 'v0.1.7'
43 changes: 32 additions & 11 deletions webifier/build/content.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pathlib
from .io_utils import read_file, data_name, prepend_baseurl
from .io_utils import read_file, data_name, prepend_baseurl, read_yaml
import yaml
from .jekyll import create_jekyll_file, create_jekyll_content_header, get_colab_url
from .notebook import generate_notebook_html
from .md import build_markdown
Expand Down Expand Up @@ -31,11 +32,26 @@ def process_content(builder, link, kind):
metadata_path = link.get('metadata', os.path.join(content_dir, 'metadata.yml'))
metadata_path = \
f'{metadata_path}{"" if metadata_path.endswith(".yml") or metadata_path.endswith(".yaml") else ".yml"}'

metadata = None
if kind == 'md':
raw_str = read_file(filename)
lines = raw_str.splitlines()
if lines[0] == '---':
try:
idx = lines.index('---', 1)
metadata = yaml.full_load('\n'.join(lines[1:idx]))
raw_str = '\n'.join(lines[idx + 1:])
except ValueError:
pass
content_str = build_markdown(builder=builder, raw=raw_str,
assets_target_dir=builder.assets_dir)
if os.path.isfile(metadata_path):
metadata = builder.build_index(
file_metadata = builder.build_index(
index_file=metadata_path.replace(".ipynb" if kind == "notebook" else ".md", ''),
assets_src_dir=content_dir, assets_target_dir=builder.assets_dir, index_type='content',
search_slug=jekyll_target_file)
metadata = file_metadata if metadata is None else {**metadata, **file_metadata}
metadata_path = data_name(index_file=metadata_path.replace(".ipynb" if kind == "notebook" else ".md", ''),
index_type='content')
if 'text' not in link:
Expand All @@ -47,19 +63,24 @@ def process_content(builder, link, kind):
link['description'] = metadata['header']['description']

else:
metadata = dict(search=builder.config['search'])
metadata_path = None
metadata_path = None if metadata is None else data_name(index_file=metadata_path.replace(
".ipynb" if kind == "notebook" else ".md", ''), index_type='content')
metadata = dict(search=builder.config['search']) if metadata is None else builder.build_index(
index=metadata, target_data_file=metadata_path.replace(".ipynb" if kind == "notebook" else ".md", ''),
assets_src_dir=content_dir, assets_target_dir=builder.assets_dir, index_type='content',
search_slug=jekyll_target_file, search_links=None, search_content=None)

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

builder.checked_content[filename] = link
content_str = generate_notebook_html(
builder=builder,
src=filename,
assets_dir=builder.assets_dir, # where to move notebook assets
search_links=metadata['search']['links']
) if kind == 'notebook' else build_markdown(builder=builder, raw=read_file(filename),
assets_target_dir=builder.assets_dir)
if kind == 'notebook':
content_str = generate_notebook_html(
builder=builder,
src=filename,
assets_dir=builder.assets_dir, # where to move notebook assets
search_links=metadata['search']['links']
)

if metadata['search']['content']:
builder.add_search_content(
jekyll_target_file, content=content_str, title=link.get('text', kind.capitalize()),
Expand Down
6 changes: 5 additions & 1 deletion webifier/build/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,18 @@ def wrapper(self, *args, **kwargs):
return wrapper


def mix_folders(root_src_dir, root_target_dir):
def mix_folders(root_src_dir, root_target_dir, file_map=None):
if root_src_dir == root_target_dir:
return
for src_dir, dirs, files in os.walk(root_src_dir):
dst_dir = src_dir.replace(root_src_dir, root_target_dir, 1)
if file_map and root_src_dir != src_dir and os.path.split(src_dir)[1] not in file_map:
continue
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)
for file_ in files:
if file_map and root_src_dir == src_dir and os.path.split(file_)[1] not in file_map:
continue
src_file = os.path.join(src_dir, file_)
dst_file = os.path.join(dst_dir, file_)
if not os.path.exists(dst_file):
Expand Down
6 changes: 1 addition & 5 deletions webifier/jekyll/_includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
class="bg-light p-3 m-auto text-center"
{% endif %}
>
{% if site.data.index.footer.first %}
{{ site.data.index.footer.text }}
{% else %}
{{ site.data.index.footer }}
{% endif %}
{{ include.footer.text | default: include.footer | default: site.data.index.footer.text | default: site.data.index.footer }}
© Powered by <a class="link-primary" href="https://github.com/webifier/build">Webifier</a>
</div>
</footer>
6 changes: 3 additions & 3 deletions webifier/jekyll/_includes/nav.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% assign colab = include.colab %}
{% if site.data.index.nav.fixed != null or site.data.index.nav.brand != null %}
{% assign links = site.data.index.nav.content %}
{% if include.nav.fixed != null or include.nav.brand != null or site.data.index.nav.fixed != null or site.data.index.nav.brand != null %}
{% assign links = include.nav.content | default: site.data.index.nav.content %}
{% else %}
{% assign links = site.data.index.nav %}
{% assign links = include.nav.content | default: site.data.index.nav.content | default: site.data.index.nav %}
{% endif %}
<nav class="px-2 navbar navbar-expand-lg navbar-light bg-light m-0 p-2 sticky-top shadow">
{% if site.data.index.nav.brand %}
Expand Down
4 changes: 2 additions & 2 deletions webifier/jekyll/_layouts/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
{% assign page_title = metadata.header.title | default: metadata.title %}
{% include header.html background=metadata.header.background title=page_title
description=metadata.header.description %}
{% include nav.html colab=page.colab %}
{% include nav.html colab=page.colab nav=metadata.nav %}
<div class="container-fluid bg-white shadow app-body {% unless page.colab %}px-5 p-4{% endunless %}">
{{ content }}
</div>
<div class="container-fluid bg-white shadow app-body">

{% include toc.html index=metadata level=1 %}
</div>
{% include footer.html background=metadata.footer.background %}
{% include footer.html background=metadata.footer.background footer=metadata.footer %}
</div>
</body>
</html>
27 changes: 9 additions & 18 deletions webifier/jekyll/assets/css/main.css
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@

body {
zoom: 130%;
zoom: 125%;
}

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

a { text-decoration: none; }

@keyframes gradient {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
.hover-shadow:hover {
filter: drop-shadow(0 0.1rem 0.3rem rgba(0,0,0, 0.5));
}
Expand All @@ -36,10 +24,7 @@ footer {

.app-content {
padding: 3vh 0;
max-width:80%;
}

.app-body {
max-width:85%;
}

.accordion-button:not(.collapsed) {
Expand All @@ -61,7 +46,13 @@ footer {
background-color: white;
}

@media only screen and (max-width: 1300px) {
@media only screen and (max-width: 1400px) {
.app-content {
max-width:95%;
}
}

@media only screen and (max-width: 1200px) {
.app-content {
max-width:100%;
}
Expand Down
9 changes: 6 additions & 3 deletions webifier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
TARGET_INDEX_FILE = 'index.yml'
DEFAULT_TEMPLATES_DIR = "."


def main():
parser = argparse.ArgumentParser(
description=f'''
Expand All @@ -25,12 +26,14 @@ def main():
parser.add_argument('--output',
dest='output', help='build target directory (default: "webified")', default=DEFAULT_OUTPUT_DIR)
parser.add_argument('--templates-dir',
dest='templates_dir', help='templates base directory (default: ".")', default=DEFAULT_TEMPLATES_DIR)
dest='templates_dir', help='templates base directory (default: ".")',
default=DEFAULT_TEMPLATES_DIR)
args = parser.parse_args()

print(f'baseurl: {args.base_url}, repo_full_name: {args.repo_full_name}')
print(f'webifier: {__version__}, baseurl: {args.base_url}, repo_full_name: {args.repo_full_name}')

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

0 comments on commit fd457ab

Please sign in to comment.