Skip to content

Commit

Permalink
Adding functionality for the bloom module to have its commands displa…
Browse files Browse the repository at this point in the history
…yed on the valkey website

Signed-off-by: zackcam <[email protected]>
  • Loading branch information
zackcam committed Feb 19, 2025
1 parent 457dbc5 commit f8cd2ec
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 26 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/zola-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ jobs:
with:
repository: valkey-io/valkey
path: valkey


- name: Checkout valkey-bloom
uses: actions/checkout@v4
with:
repository: valkey-io/valkey-bloom
path: valkey-bloom

- name: Init commands and topics
run: |
cd website
./build/init-topics.sh ../valkey-doc/topics
./build/init-commands.sh ../valkey-doc/commands ../valkey/src/commands
./build/init-commands.sh ../valkey-doc/commands ../valkey/src/commands ../valkey-bloom/src/commands
- name: Build only
uses: shalzz/[email protected]
env:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Valkey.io website

This repo contains the source for the valkey.io website (build scripts, template, blog posts, stylesheets, etc.).
The build integrates content from [`valkey-io/valkey-doc`](https://github.com/valkey-io/valkey-doc) and the commands definitions from [`valkey-io/valkey`](https://github.com/valkey-io/valkey) (see [Build Locally](#build-locally) below for more details).
The build integrates content from [`valkey-io/valkey-doc`](https://github.com/valkey-io/valkey-doc) and the commands definitions from [`valkey-io/valkey`](https://github.com/valkey-io/valkey) and [`valkey-io/valkey-bloom`](https://github.com/valkey-io/valkey-bloom) (see [Build Locally](#build-locally) below for more details).

## Contributing

Expand Down Expand Up @@ -62,8 +62,8 @@ Commit your changes to your local copy of `valkey-io/valkey-doc`.

### Building the command reference

The command reference (i.e. `/commands/set/`, `/commands/get/`, `/commands/lolwut/`) sources information from `valkey-io/valkey`, and `valkey-io/valkey-doc`.
`valkey-io/valkey` provides the command metadata (items like computational complexity, version history, arguments, etc) whilst `valkey-io/valkey-doc` provides the command description and the command reply.
The command reference (i.e. `/commands/set/`, `/commands/get/`, `/commands/lolwut/`) sources information from `valkey-io/valkey`, `valkey-io/valkey-bloom`, and `valkey-io/valkey-doc`.
`valkey-io/valkey` and `valkey-io/valkey-bloom` provides the command metadata (items like computational complexity, version history, arguments, etc) whilst `valkey-io/valkey-doc` provides the command description and the command reply.

```mermaid
flowchart TD
Expand All @@ -74,13 +74,13 @@ flowchart TD
H --> J[Files: /resp2_replies.json,<br/>/resp3_replies.json] --> Z[Command Reply]
```

Let's say that this repo and your local copy of `valkey-io/valkey-doc` and `valkey-io/valkey` reside in the same directories.
Let's say that this repo and your local copy of `valkey-io/valkey-doc`, `valkey-io/valkey-bloom` and `valkey-io/valkey` reside in the same directories.
First, stop the `zola serve` process if you're running it.
From the root directory of this repo run:

```shell
# You should only need to run this once or when you add a new command.
./build/init-commands.sh ../valkey-doc/commands ../valkey/src/commands
./build/init-commands.sh ../valkey-doc/commands ../valkey/src/commands ../valkey-bloom/src/commands
```

Then, restart Zola.
Expand Down
14 changes: 12 additions & 2 deletions build/init-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,30 @@ if [ ! -d "$2" ]; then
exit 1
fi

if [ ! -d "$3" ]; then
echo "The bloom module command JSON directory must exist and be a valid path"
exit 1
fi

ln -s $1 ./build-command-docs
ln -s $2 ./build-command-json

ln -s $3 ./build-bloom-command-json
for fname in $(find $1 -maxdepth 1 -iname "*.md")
do
base=${fname##*/}
command=${base%.*}
command_upper=$(awk '{ print toupper($0) }' <<< $command)
if [[ "$command" != "index" ]]; then
if [ -f "$2/$command.json" ]; then
metadata_path="/commands/$command.json in the 'valkey' repo"
elif [ -f "$3/$command.json" ]; then
metadata_path="/commands/$command.json in the 'valkey-bloom' repo"
fi
cat << EOF > "./content/commands/$command.md"
+++
# This is a generated stub file.
# To edit the command description see /commands/$command.md in the 'valkey-doc' repo
# The command metadata is generated from /src/$command.json in the 'valkey' repo
# The command metadata is generated from $metadata_path
aliases = ["/commands/$command_upper/"]
+++
EOF
Expand Down
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ highlight_code = true
[extra]
command_description_path = "../build-command-docs/"
command_json_path = "../build-command-json/"
command_bloom_json_path = "../build-bloom-command-json/"
doc_topic_path = "../build-topics/"

review_list = [
Expand Down
8 changes: 7 additions & 1 deletion templates/command-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
{% set upper_slug = page.slug | upper %}

{% set command_description = load_data(path=config.extra.command_description_path ~ page.slug ~ ".md", required= false) %}
{% set command_data = load_data(path= commands::command_json_path(slug= page.slug), required= false) %}
{% set command_sources = [
load_data(path= commands::command_json_path(slug= page.slug), required= false),
load_data(path= commands::command_bloom_json_path(slug= page.slug), required= false)
] %}

{% set command_data = command_sources | filter(attribute="") | first %}

{% if command_data %}
{% set command_obj_name = commands::command_obj_name(command_data= command_data) %}
{% set command_data_obj = command_data[command_obj_name] %}
Expand Down
36 changes: 20 additions & 16 deletions templates/commands.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@

{% set commands_entries = [] %}
{% for page in section.pages %}
{% set command_data = load_data(path= commands::command_json_path(slug= page.slug), required= false) %}
{% if command_data %}
{% set command_obj_name = commands::command_obj_name(command_data= command_data) %}
{% set command_data_obj = command_data[command_obj_name] %}
{% set command_display = command_obj_name %}
{% if command_data_obj.container %}
{% set command_display = command_data_obj.container ~ " " ~ command_display %}
{% for json_path in [
commands::command_json_path(slug=page.slug),
commands::command_bloom_json_path(slug=page.slug)
] %}
{% set command_data = load_data(path= json_path, required= false) %}
{% if command_data %}
{% set command_obj_name = commands::command_obj_name(command_data= command_data) %}
{% set command_data_obj = command_data[command_obj_name] %}
{% set command_display = command_obj_name %}
{% if command_data_obj.container %}
{% set command_display = command_data_obj.container ~ " " ~ command_display %}
{% endif %}
{% set command_entry = [
command_display,
page.permalink | safe,
command_data_obj.summary,
command_data_obj.group
] %}
{% set_global commands_entries = commands_entries | concat(with= [ command_entry ]) %}
{% endif %}

{% set command_entry = [
command_display,
page.permalink | safe,
command_data_obj.summary,
command_data_obj.group
] %}
{% set_global commands_entries = commands_entries | concat(with= [ command_entry ]) %}
{% endif %}
{% endfor %}
{% endfor %}
{% set_global grouped = commands_entries | sort(attribute="3") | group_by(attribute="3") %}

Expand Down
4 changes: 4 additions & 0 deletions templates/macros/command.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
{{config.extra.command_json_path }}{{ slug }}.json
{%- endmacro load_command_json -%}

{%- macro command_bloom_json_path(slug) -%}
{{config.extra.command_bloom_json_path }}{{ slug }}.json
{%- endmacro load_bloom_command_json -%}

{%- macro fix_links(content) -%}
{{ content
| regex_replace(pattern=`\]\(\.\./topics/(?P<fname>.*?).md#(?P<hash>.*?)\)`, rep=`](/topics/$fname#$hash)`)
Expand Down

0 comments on commit f8cd2ec

Please sign in to comment.