Skip to content

Commit

Permalink
Merge pull request #26 from carlopi/fix_docs
Browse files Browse the repository at this point in the history
Improve docs markdown generation, allow example and extended
  • Loading branch information
carlopi committed Jul 3, 2024
2 parents 5178ed5 + 484bde3 commit fda37d9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 29 deletions.
8 changes: 7 additions & 1 deletion extensions/quack/description.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ extension:

repo:
github: hannes/quack
ref: 09680a975bcf9e93b5a2f46d3eeb68792d5239c6
ref: 09680a975bcf9e93b5a2f46d3eeb68792d5239c6

docs:
hello_world: |
SELECT quack('world');
extended_description: |
The quack extension is based on DuckDB's [Extension Template](https://duckdb/extension_template/), and it's a great starting point to get started building more advanced extensions.
18 changes: 18 additions & 0 deletions layout/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

### Installing and Loading
```sql
INSTALL {{ page.extension.name }} FROM community;
LOAD {{ page.extension.name }};
```

{% if page.docs.hello_world %}
### Example
```sql
{{ page.docs.hello_world }}```
{% endif %}

{% if page.docs.extended_description %}
### About {{ page.extension.name }}
{{ page.docs.extended_description }}
{% endif %}

62 changes: 34 additions & 28 deletions scripts/generate_md.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,44 @@ do
rm -f pre.db
rm -f post.db

if [ -s "$DOCS/$extension/extension.md" ]; then
echo "## $extension" > $EXTENSION_README
echo "" >> $EXTENSION_README
cat $DOCS/$extension/extension.md >> $EXTENSION_README
echo "---" > $EXTENSION_README
echo "layout: community_extension" >> $EXTENSION_README
echo "title: $extension" >> $EXTENSION_README
if [ -s "extensions/$extension/description.yml" ]; then
cat extensions/$extension/description.yml >> $EXTENSION_README
echo "" >> $EXTENSION_README
echo -n "extension_star_count: " >> $EXTENSION_README
python3 scripts/get_stars.py extensions/$extension/description.yml $1 >> $EXTENSION_README
fi
echo "---" >> $EXTENSION_README
cat layout/default.md >> $EXTENSION_README

if [ -s "$DOCS/$extension/functions.md" ]; then
echo "### Added functions" >> $EXTENSION_README
echo "" >> $EXTENSION_README
cat $DOCS/$extension/functions.md >> $EXTENSION_README
echo "" >> $EXTENSION_README
fi
if [ -s "$DOCS/$extension/functions_overloads.md" ]; then
echo "### Added function overloads" >> $EXTENSION_README
echo "" >> $EXTENSION_README
cat $DOCS/$extension/functions_overloads.md >> $EXTENSION_README
echo "" >> $EXTENSION_README
fi
if [ -s "$DOCS/$extension/types.md" ]; then
echo "### Added types" >> $EXTENSION_README
echo "" >> $EXTENSION_README
cat $DOCS/$extension/types.md >> $EXTENSION_README
echo "" >> $EXTENSION_README
fi
if [ -s "$DOCS/$extension/settings.md" ]; then
echo "### Added settings" >> $EXTENSION_README
echo "" >> $EXTENSION_README
cat $DOCS/$extension/settings.md >> $EXTENSION_README
echo "" >> $EXTENSION_README
fi
if [ -s "$DOCS/$extension/functions.md" ]; then
echo "### Added functions" >> $EXTENSION_README
echo "" >> $EXTENSION_README
cat $DOCS/$extension/functions.md >> $EXTENSION_README
echo "" >> $EXTENSION_README
fi
if [ -s "$DOCS/$extension/functions_overloads.md" ]; then
echo "### Added function overloads" >> $EXTENSION_README
echo "" >> $EXTENSION_README
cat $DOCS/$extension/functions_overloads.md >> $EXTENSION_README
echo "" >> $EXTENSION_README
fi
if [ -s "$DOCS/$extension/types.md" ]; then
echo "### Added types" >> $EXTENSION_README
echo "" >> $EXTENSION_README
cat $DOCS/$extension/types.md >> $EXTENSION_README
echo "" >> $EXTENSION_README
fi
if [ -s "$DOCS/$extension/settings.md" ]; then
echo "### Added settings" >> $EXTENSION_README
echo "" >> $EXTENSION_README
cat $DOCS/$extension/settings.md >> $EXTENSION_README
echo "" >> $EXTENSION_README
fi
echo "" >> $EXTENSION_README

rm -rf $DOCS/$extension
done

Expand Down
14 changes: 14 additions & 0 deletions scripts/get_stars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
import yaml
import subprocess

desc_file = sys.argv[1]
duckdb = sys.argv[2]

with open(desc_file, 'r') as stream:
desc = yaml.safe_load(stream)

subprocess.run([duckdb, "-c", "COPY (SELECT ' ') TO 'build/stars.csv' (HEADER FALSE);"])
subprocess.run([duckdb, "-c", "COPY (SELECT stargazers_count FROM read_json('https://api.github.com/repos/" + desc['repo']['github'] + "')) TO 'build/stars.csv' (HEADER FALSE);"])
subprocess.run(["cat", "build/stars.csv"])

0 comments on commit fda37d9

Please sign in to comment.