Skip to content

Commit 7cfcdb6

Browse files
committed
customize top navigation links and to create submenus in shell
1 parent 5d27a86 commit 7cfcdb6

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Fix a bug where the new geojson support in the map component would not work when the geojson was passed as a string. This impacted databases that do not support native json objects, such as SQLite.
66
- Improve support for geojson points (in addition to polygons and lines) in the map component.
77
- Add a new `size` parameter to the map component to set the size of markers.
8+
- Add the ability to customize top navigation links and to create submenus in the `shell` component.
89

910
## 0.15.1 (2023-11-07)
1011

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
500500
('javascript', 'The URL of a Javascript file to load and execute on the page.', 'URL', TRUE, TRUE),
501501
('image', 'The URL of an image to display next to the page title.', 'URL', TRUE, TRUE),
502502
('icon', 'Name of an icon (from tabler-icons.io) to display next to the title in the navigation bar.', 'ICON', TRUE, TRUE),
503-
('menu_item', 'Adds a menu item in the navigation bar at the top of the page. The menu item will have the specified name, and will link to as .sql file of the same name.', 'TEXT', TRUE, TRUE),
503+
('menu_item', 'Adds a menu item in the navigation bar at the top of the page. The menu item will have the specified name, and will link to as .sql file of the same name. A dropdown can be generated by passing a json object with a `title` and `submenu` properties.', 'TEXT', TRUE, TRUE),
504504
('search_target', 'When this is set, a search field will appear in the top navigation bar, and load the specified sql file with an URL parameter named "search" when the user searches something.', 'TEXT', TRUE, TRUE),
505505
('norobot', 'Forbids robots to save this page in their database and follow the links on this page. This will prevent this page to appear in Google search results for any query, for instance.', 'BOOLEAN', TRUE, TRUE),
506506
('font', 'Name of a font to display the text in. This has to be a valid font name from fonts.google.com.', 'TEXT', TRUE, TRUE),
@@ -512,12 +512,30 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
512512
) x;
513513

514514
INSERT INTO example(component, description, properties) VALUES
515-
('shell', 'This example contains the values used for the shell of the page you are currently viewing.',
515+
('shell', '
516+
This example contains the values used for the shell of the page you are currently viewing.
517+
518+
The `menu_item` property is used both in its simple string form, to generate a link named "functions" that points to "functions.sql",
519+
and in its object form, to generate a dropdown menu named "Community" with links to the blog, the github repository, and the issues page.
520+
521+
The object form can be used directly only on database engines that have a native JSON type.
522+
On other engines (such as SQLite), you can use the `dynamic` component to generate the same result.
523+
',
516524
json('[{
517525
"component": "shell",
518526
"title": "SQLPage documentation",
519527
"link": "/",
520-
"menu_item": ["index", "blog", "components", "functions"],
528+
"menu_item": [
529+
{"link": "index.sql", "title": "Home"},
530+
{"title": "Community", "submenu": [
531+
{"link": "blog.sql", "title": "Blog"},
532+
{"link": "//github.com/lovasoa/sqlpage/issues", "title": "Issues"},
533+
{"link": "//github.com/lovasoa/sqlpage/discussions", "title": "Discussions"},
534+
{"link": "//github.com/lovasoa/sqlpage", "title": "Github"}
535+
]},
536+
"functions",
537+
"components"
538+
],
521539
"language": "en-US",
522540
"description": "Documentation for the SQLPage low-code web application framework.",
523541
"font": "Poppins",

sqlpage/templates/shell.handlebars

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,29 @@
6060
<div class="collapse navbar-collapse" id="navbar-menu">
6161
<ul class="navbar-nav ms-auto">
6262
{{#each (to_array menu_item)}}
63-
<li class="nav-item">
64-
<a class="nav-link text-capitalize" href="{{this}}.sql">{{this}}</a>
65-
</li>
63+
{{#if (eq (typeof this) 'object')}}
64+
<li class="nav-item{{#if this.submenu}} dropdown{{/if}}">
65+
<a class="nav-link {{#if this.submenu}}dropdown-toggle{{/if}}" href="{{#if this.link}}{{this.link}}{{else}}#{{/if}}"
66+
{{#if this.submenu}}data-bs-toggle="dropdown" data-bs-auto-close="outside"{{/if}}
67+
role="button"
68+
>
69+
{{this.title}}
70+
</a>
71+
{{#if this.submenu}}
72+
<div class="dropdown-menu dropdown-menu-end" data-bs-popper="static">
73+
{{#each this.submenu}}
74+
<a class="dropdown-item" href="{{this.link}}">
75+
{{this.title}}
76+
</a>
77+
{{/each}}
78+
</div>
79+
{{/if}}
80+
</li>
81+
{{else}}
82+
<li class="nav-item">
83+
<a class="nav-link text-capitalize" href="{{this}}.sql">{{this}}</a>
84+
</li>
85+
{{/if}}
6686
{{/each}}
6787
</ul>
6888
{{#if search_target}}

0 commit comments

Comments
 (0)