|
| 1 | +--- |
| 2 | +title: "Dynamic content" |
| 3 | +date: 2025-09-09 |
| 4 | +tags: ["Contribute"] |
| 5 | +showTableOfContents: true |
| 6 | +showAuthor: false |
| 7 | +authors: |
| 8 | + - "kirill-chalov" |
| 9 | +--- |
| 10 | + |
| 11 | +For pages that change frequently, it is useful to bypass git and inject the updated content dynamically instead of creating PRs every time. As of now, this is helpful for hardware and software product support pages that can update weekly. This article will provide a workflow for injecting dynamic content focusing on the product support pages. |
| 12 | + |
| 13 | + |
| 14 | +## Plan your page |
| 15 | + |
| 16 | +First of all, the content on a product support page should be classified into the following types: |
| 17 | + |
| 18 | +- **Static**: Rarely changing content |
| 19 | + - Committed to the git repo |
| 20 | + - Stored under |
| 21 | + `content/{hardware|software}/product-x/index.md` |
| 22 | +- **Dymanic**: Frequently changing content |
| 23 | + - Dynamically injected into HTML pages using the [dynamic-block](https://github.com/espressif/developer-portal/blob/main/layouts/shortcodes/dynamic-block.html) shortcode |
| 24 | + - Stored in the root of the web server under |
| 25 | + `./persist/{hardware|software}/product-x/product-x.json` |
| 26 | + - Updated either manually or using CI |
| 27 | + - For uploading to the web server, talk to the project maintainers |
| 28 | + |
| 29 | +The dynamic content must be stored in the root of the web server under `persist`. All other folders are fully overwritten daily. |
| 30 | + |
| 31 | + |
| 32 | +## Arrange your content |
| 33 | + |
| 34 | +Example files: |
| 35 | + |
| 36 | +- Git repo: `content/software/product-x/index.md` |
| 37 | + ``` |
| 38 | + --- |
| 39 | + title: "Product X" |
| 40 | + date: 2025-08-28 |
| 41 | + --- |
| 42 | +
|
| 43 | + **Last updated:** {{</* dynamic-block contentPath="persist/software/product-x/product-x.json" jsonKey="timestamp" */>}} |
| 44 | +
|
| 45 | + This is a product status page for Product X. |
| 46 | +
|
| 47 | + The following features are supported as of now: |
| 48 | +
|
| 49 | + {{</* dynamic-block contentPath="persist/software/product-x/product-x.json" jsonKey="feature_table" */>}} |
| 50 | +
|
| 51 | + ## Peripheral support table |
| 52 | +
|
| 53 | + {{</* dynamic-block contentPath="persist/software/product-x/product-x.json" jsonKey="periph_support_table" */>}} |
| 54 | + ``` |
| 55 | +- Web server: `persist/software/product-x/product-x.json` |
| 56 | + ```json |
| 57 | + { |
| 58 | + "timestamp": "2025-08-28T00:07:19.716630Z", |
| 59 | + "feature_list": "- Supported SDKs\n - ✅ [ESP-IDF](https://github.com/espressif/esp-idf/)\n - ⏳ SDK 2", |
| 60 | + "periph_support_table": "| Peripheral | ESP32 |\n| :--- | :---: |\n| UART | ✅ |\n| LCD | ❌ |" |
| 61 | + } |
| 62 | + ``` |
| 63 | + |
| 64 | +The final page with the dynamic content should look somewhat like this: |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +<span style="font-size:2em; font-weight:bold;">Product X</span> |
| 69 | + |
| 70 | +**Last updated:** 28 Aug 2025, 8:07 am |
| 71 | + |
| 72 | +This is a product status page for Product X. |
| 73 | + |
| 74 | +The following features are supported as of now: |
| 75 | + |
| 76 | +- Supported SDKs |
| 77 | + - ✅ [ESP-IDF](https://github.com/espressif/esp-idf/) |
| 78 | + - ⏳ SDK 2 |
| 79 | + |
| 80 | +<span style="font-size:1.5em; font-weight:bold;">Peripheral support table</span> |
| 81 | + |
| 82 | +| Peripheral | ESP32 | |
| 83 | +| :--- | :---: | |
| 84 | +| UART | ✅ | |
| 85 | +| LCD | ❌ | |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | + |
| 90 | +## Test dynamic content |
| 91 | + |
| 92 | +Test your `.json` file locally before uploading to the web server: |
| 93 | + |
| 94 | +- In your git repo, place your `.json` file at the same path as on the server: |
| 95 | + ```sh |
| 96 | + 📂 content/software/ |
| 97 | + ├── 📝 _index.md |
| 98 | + └── 📂 product-x/ |
| 99 | + ├── 📝 index.md |
| 100 | + └── 🧩 persist/software/product-x/product-x.json # remove after testing |
| 101 | + ``` |
| 102 | +- In your git repo's `layouts/shortcodes/dynamic-block.html`, adjust the toggle for testing: |
| 103 | + ```javascript |
| 104 | + {{ $localMode := true }} <!-- change to true for local --> |
| 105 | + ``` |
| 106 | + |
| 107 | +After you run `hugo server` locally, the JSON content should be injected dynamically on your page. |
| 108 | + |
| 109 | +**If you update JSON**, do this for the changes to show up: |
| 110 | + |
| 111 | +- Restart `hugo server` |
| 112 | +- Refresh your browser tab |
| 113 | +- If no effect: clear the page cache |
0 commit comments