-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate_website function created (wip)
- Loading branch information
paul.marcombes
committed
Oct 21, 2024
1 parent
cc5f0ad
commit 2651457
Showing
1 changed file
with
133 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
type: function_py | ||
category: wip | ||
author: | ||
name: Paul Marcombes | ||
url: https://www.linkedin.com/in/paul-marcombes | ||
avatar_url: "https://lh3.googleusercontent.com/a/ACg8ocIAw-jJTmt7AkDhU6_OvDQwsy9uyuRiWX8MxUBOdpro8lRJEgk5=s288-c-no" | ||
description: Request `url` | ||
arguments: | ||
- name: assets | ||
type: json | ||
output: | ||
name: response | ||
type: string | ||
examples: | ||
- description: "Without headers" | ||
arguments: | ||
- "[1]" | ||
output: "<html>...</html>" | ||
- description: "With Content-Type = application/json headers" | ||
arguments: | ||
- "'https://api.github.com/repos/unytics/bigfunctions'" | ||
- "json '{\"Content-Type\": \"application/json\"}'" | ||
output: "{...}" | ||
init_code: | | ||
import os | ||
import tempfile | ||
import re | ||
import shutil | ||
import mkdocs.config | ||
import mkdocs.commands.build | ||
import jinja2 | ||
MKDOCS_YAML_TEMPLATE = ''' | ||
site_name: Gitlab Team dbt | ||
site_url: http://catalogs.unytics.io/dbt_gitlab_data_team/ | ||
site_dir: {{ site_dir }} | ||
docs_dir: {{ docs_dir }} | ||
extra_css: | ||
- extra/style.css | ||
nav: | ||
- ... | ||
theme: | ||
name: material | ||
favicon: https://about.gitlab.com/nuxt-images/ico/favicon.ico | ||
logo: https://cdn-icons-png.flaticon.com/256/5968/5968853.png | ||
palette: | ||
primary: black | ||
features: | ||
- navigation.instant | ||
- navigation.tabs | ||
- navigation.prune | ||
- navigation.indexes | ||
- content.tabs.link | ||
markdown_extensions: | ||
- attr_list | ||
- md_in_html | ||
- admonition | ||
- pymdownx.details | ||
- pymdownx.superfences | ||
- pymdownx.tabbed: | ||
alternate_style: true | ||
- pymdownx.emoji: | ||
emoji_index: !!python/name:material.extensions.emoji.twemoji | ||
emoji_generator: !!python/name:material.extensions.emoji.to_svg | ||
plugins: | ||
- search | ||
- awesome-pages | ||
''' | ||
TEMPLATE = jinja2.Template(''' | ||
# {{ name }} | ||
<div class="grid cards" markdown> | ||
{% for review in reviews %} | ||
- **{{ review.title | replace('\n', '') }}** | ||
--- | ||
{{ review.content | indent(4) }} | ||
{{ review.rating * ':star: ' }} | ||
{% endfor %} | ||
</div> | ||
''') | ||
code: | | ||
if not assets: | ||
return 'no asset given' | ||
assert isinstance(assets, list), 'Given `assets` must be a json array of strings or objects' | ||
assert all('path' in asset for asset in assets), 'All `assets` must have a `path` field' | ||
with tempfile.TemporaryDirectory() as folder: | ||
docs_dir = f'{folder}/docs' | ||
for asset in assets: | ||
path = asset['path'] | ||
if not path: | ||
continue | ||
path = re.sub(r'[^a-zA-Z0-9_\- /]', '', path) | ||
path = path.strip().strip('/') | ||
name = path.split('/')[-1] | ||
path += '.md' | ||
filename = f'{docs_dir}/{path}' | ||
file_folder = '/'.join(filename.split('/')[:-1]) | ||
os.makedirs(file_folder, exist_ok=True) | ||
content = TEMPLATE.render(name=name, **asset) | ||
with open(filename, 'w', encoding='utf-8') as f: | ||
f.write(content) | ||
mkdocs_yaml_filename = f'{folder}/mkdocs.yaml' | ||
site_dir = f'/storage/public/site' | ||
mkdocs_yaml = MKDOCS_YAML_TEMPLATE.replace('{{ site_dir }}', site_dir).replace('{{ docs_dir }}', docs_dir) | ||
with open(mkdocs_yaml_filename, 'w', encoding='utf-8') as f: | ||
f.write(mkdocs_yaml) | ||
shutil.rmtree(site_dir, ignore_errors=True) | ||
config = mkdocs.config.load_config(mkdocs_yaml_filename) | ||
mkdocs.commands.build.build(config) | ||
return 'ok' | ||
requirements: | | ||
jinja2 | ||
mkdocs-material | ||
mkdocs-awesome-pages-plugin | ||
quotas: | ||
max_rows_per_query: 10 | ||
cloud_run: | ||
memory: 1024Mi | ||
concurrency: 1 | ||
max_instances: 10 | ||
add_volume: '"name=storage,type=cloud-storage,bucket=catalogs.unytics.io"' | ||
add_volume_mount: '"volume=storage,mount-path=/storage"' | ||
execution-environment: gen2 |