Skip to content

Commit 4d26acf

Browse files
committed
Move the shell reference and navigation examples to Markdown
1 parent 5177685 commit 4d26acf

8 files changed

Lines changed: 422 additions & 282 deletions

File tree

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
icon: layout-navbar
3+
category: page-layout
4+
summary: Set the page layout, navigation, branding, and footer.
5+
top:
6+
- name: class
7+
type: TEXT
8+
description: class attribute added to the page's html element. It can be used to apply custom styling to
9+
the whole page through css.
10+
- name: css
11+
type: URL
12+
description: The URL of a CSS file to load and apply to the page.
13+
- name: description
14+
type: TEXT
15+
description: A description of the page. It can be displayed by search engines when your page appears in
16+
their results.
17+
- name: favicon
18+
type: URL
19+
description: The URL of the icon the web browser should display in bookmarks and tabs. This property is
20+
particularly useful if multiple sites are hosted on the same domain with different [``site_prefix``](https://github.com/sqlpage/SQLPage/blob/main/configuration.md#configuring-sqlpage).
21+
- name: fixed_top_menu
22+
type: BOOLEAN
23+
description: Fixes the top bar with menu at the top (the top bar remains visible when scrolling long pages).
24+
- name: font
25+
type: TEXT
26+
description: Specifies the font to be used for displaying text, which can be a valid font name from fonts.google.com
27+
or the path to a local WOFF2 font file starting with a slash (e.g., "/fonts/MyLocalFont.woff2").
28+
- name: font_size
29+
type: INTEGER
30+
description: Font size on the page, in pixels. Set to 18 by default.
31+
- name: footer
32+
type: TEXT
33+
description: Muted text to display in the footer of the page. This can be used to display a link to the
34+
terms and conditions of your application, for instance. By default, shows "Built with SQLPage". Supports
35+
links with markdown.
36+
- name: icon
37+
type: ICON
38+
description: Name of an icon (from tabler-icons.io) to display next to the title in the navigation bar.
39+
- name: image
40+
type: URL
41+
description: The URL of an image to display next to the page title.
42+
- name: javascript
43+
type: URL
44+
description: The URL of a Javascript file to load and execute on the page.
45+
- name: javascript_module
46+
type: URL
47+
description: The URL of a javascript module in the ESM format (see javascript.info/modules)
48+
- name: language
49+
type: TEXT
50+
description: The language of the page. This can be used by search engines and screen readers to determine
51+
in which language the page is written.
52+
- name: layout
53+
type: TEXT
54+
description: The general page layout. Can be "boxed" (the default), "horizontal" (for a full-width menu),
55+
"vertical"(vertical menu), "fluid" (removes side margins).
56+
- name: link
57+
type: URL
58+
description: The target of the link in the top navigation bar.
59+
- name: manifest
60+
type: URL
61+
description: The location of the [manifest.json](https://developer.mozilla.org/en-US/docs/Web/Manifest)
62+
if the site is a [PWA](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps). Among other
63+
features, serving a manifest enables your site to be "installed" as an app on most mobile devices.
64+
- name: menu_item
65+
type: TEXT
66+
description: Adds a menu item in the navigation bar at the top of the page. The menu item will have the
67+
specified name, and will link to as .sql file of the same name. A dropdown can be generated by passing
68+
a json object with a `title` and `submenu` properties.
69+
- name: navbar_title
70+
type: TEXT
71+
description: The title shown in the navigation bar or sidebar. Defaults to the page title. Set an empty
72+
string to show just the logo.
73+
- name: navbar_toggle_label
74+
type: TEXT
75+
description: Customizes the accessible name of the button that opens and closes the navigation menu on small
76+
screens, which screen readers announce. Replaces the default "Toggle navigation".
77+
- name: norobot
78+
type: BOOLEAN
79+
description: Forbids robots to save this page in their database and follow the links on this page. This
80+
will prevent this page to appear in Google search results for any query, for instance.
81+
- name: preview_image
82+
type: URL
83+
description: The URL of an image to display as a link preview when the page is shared on social media
84+
- name: refresh
85+
type: INTEGER
86+
description: Number of seconds after which the page should refresh. This can be useful to display dynamic
87+
content that updates automatically.
88+
- name: rss
89+
type: URL
90+
description: The URL of an RSS feed to display in the top navigation bar. You can use the rss component
91+
to generate the field.
92+
- name: rtl
93+
type: BOOLEAN
94+
description: Whether the page should be displayed in right-to-left mode. Used to display Arabic, Hebrew,
95+
Persian, etc.
96+
- name: search_button
97+
type: TEXT
98+
description: Customizes the text displayed on the search button. Replaces the default "Search" label with
99+
custom text that may better match your applications terminology or language.
100+
- name: search_placeholder
101+
type: TEXT
102+
description: Customizes the placeholder text shown in the search input field. Replaces the default "Search"
103+
with text that better describes what users should search for. It is also used as the accessible name
104+
of the search field, which screen readers announce.
105+
- name: search_target
106+
type: TEXT
107+
description: When this is set, a search field will appear in the top navigation bar, and load the specified
108+
sql file with an URL parameter named "search" when the user searches something.
109+
- name: search_value
110+
type: TEXT
111+
description: This value will be placed in the search field when "search_target" is set. Using the "$search"
112+
query parameter value will mirror the value that the user has searched for.
113+
- name: sidebar
114+
type: BOOLEAN
115+
description: Whether the menu defined by menu_item should be displayed on the left side of the page instead
116+
of the top. Introduced in v0.27.
117+
- name: sidebar_theme
118+
type: TEXT
119+
description: Used with sidebar property, It can be set to "dark" to exclusively set the sidebar into dark
120+
theme.
121+
- name: social_image
122+
type: URL
123+
description: The URL of the preview image that will appear in the Open Graph metadata when the page is
124+
shared on social media.
125+
- name: target
126+
type: TEXT
127+
description: 'Where the menu items should open: "_blank" for a new tab, "_self" for the same tab, "_parent"
128+
for the parent frame, or "_top" for the full body of the window. Set it inside a "menu_item" json object;
129+
it has no effect when set directly on the shell.'
130+
- name: theme
131+
type: TEXT
132+
description: Set to "dark" to use a dark theme.
133+
- name: title
134+
type: TEXT
135+
description: The title of your page. Will be shown in a top bar above the page contents. Also usually displayed
136+
by web browsers as the name of the web page's tab.
137+
---
138+
139+
Customize the overall layout, header and footer of the page.
140+
141+
This is a special component that provides the page structure wrapping all other components on your page.
142+
143+
It generates the complete HTML document including the `<head>` section with metadata, title, and stylesheets,
144+
as well as the navigation bar, main content area, and footer.
145+
146+
If you don't explicitly call the shell component at the top of your SQL file, SQLPage will automatically
147+
add a default shell component before your first try to display data on the page.
148+
149+
Use the shell component to customize page-wide settings like the page title, navigation menu, theme, fonts,
150+
and to include custom visual styles (with CSS) or interactive behavior (with JavaScript) that should be loaded on the page.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
rows:
3+
- component: shell
4+
title: 'SQLPage: SQL websites'
5+
navbar_title: SQLPage
6+
link: /
7+
menu_item:
8+
- title: About
9+
submenu:
10+
- link: /safety.sql
11+
title: Security
12+
icon: lock
13+
- link: /performance.sql
14+
title: Performance
15+
icon: bolt
16+
- link: //github.com/sqlpage/SQLPage/blob/main/LICENSE.txt
17+
title: License
18+
icon: file-text
19+
- link: /blog.sql
20+
title: Articles
21+
icon: book
22+
- title: Examples
23+
submenu:
24+
- link: /examples/tabs/
25+
title: Tabs
26+
icon: layout-navbar
27+
- link: /examples/layouts.sql
28+
title: Layouts
29+
icon: layout
30+
- link: /examples/multistep-form
31+
title: Forms
32+
icon: edit
33+
- link: /examples/handle_picture_upload.sql
34+
title: File uploads
35+
icon: upload
36+
- link: /examples/authentication/
37+
title: Password protection
38+
icon: password-user
39+
- link: //github.com/sqlpage/SQLPage/blob/main/examples/
40+
title: All examples & demos
41+
icon: code
42+
- title: Community
43+
submenu:
44+
- link: /blog.sql
45+
title: Blog
46+
icon: book
47+
- link: //github.com/sqlpage/SQLPage/issues
48+
title: Report a bug
49+
icon: bug
50+
- link: //github.com/sqlpage/SQLPage/discussions
51+
title: Discussions
52+
icon: message
53+
- link: //github.com/sqlpage/SQLPage
54+
title: Github
55+
icon: brand-github
56+
- title: Documentation
57+
submenu:
58+
- link: /your-first-sql-website
59+
title: Getting started
60+
icon: book
61+
- link: /components.sql
62+
title: All Components
63+
icon: list-details
64+
- link: /functions.sql
65+
title: SQLPage Functions
66+
icon: math-function
67+
- link: /extensions-to-sql
68+
title: Extensions to SQL
69+
icon: cube-plus
70+
- link: /custom_components.sql
71+
title: Custom Components
72+
icon: puzzle
73+
- link: //github.com/sqlpage/SQLPage/blob/main/configuration.md#configuring-sqlpage
74+
title: Configuration
75+
icon: settings
76+
- title: Search
77+
link: /search
78+
layout: boxed
79+
language: en-US
80+
description: Go from SQL queries to web applications in an instant.
81+
preview_image: https://sql-page.com/sqlpage_social_preview.webp
82+
theme: dark
83+
font_size: 19
84+
image: /assets/icon.webp
85+
favicon: /favicon.ico
86+
javascript_module: /assets/highlightjs-launch.js
87+
css: /assets/highlightjs-and-tabler-theme.css
88+
footer: '[Built with SQLPage](https://github.com/sqlpage/SQLPage/tree/main/examples/official-site)'
89+
---
90+
91+
This example configures a dark shell with menus linking to pages on this site.
92+
93+
Each `menu_item` object defines a link or a dropdown. The "Community" menu links to the blog, issue tracker, discussions, and source code.
94+
95+
The object form can be used directly only on database engines that have a native JSON type.
96+
On other engines (such as SQLite), you can use the [`dynamic`](?component=dynamic#component) component to generate the same result.
97+
98+
99+
You see the [page layouts demo](./examples/layouts.sql) for a live example of the different layouts.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
rows:
3+
- component: shell
4+
title: 'SQLPage: SQL websites'
5+
icon: database
6+
link: /
7+
menu_item:
8+
- title: Home
9+
active: true
10+
- title: About
11+
---
12+
13+
This example shows how to set menu items as active in the navigation, so that they are highlighted in the nav bar.
14+
15+
In this example you can see that two menu items are created, "Home" and "About" and the "Home" tab is marked as active.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
### Sharing the shell between multiple pages
2+
3+
It is common to want to share the same shell between multiple pages.
4+
5+
#### Static menu
6+
7+
If your menu is completely static (it does not depend on the database content),
8+
you can use the [`dynamic`](?component=dynamic#component) component together with the
9+
[`sqlpage.read_file_as_text`](functions.sql?function=read_file_as_text#function) function to load the shell from
10+
a json file.
11+
12+
```sql
13+
SELECT 'dynamic' AS component, sqlpage.read_file_as_text('shell.json') AS properties;
14+
```
15+
16+
and in `shell.json`:
17+
18+
```json
19+
{
20+
"component": "shell",
21+
"title": "SQL + JSON = <3",
22+
"link": "/",
23+
"menu_item": [
24+
{"link": "index.sql", "title": "Home"},
25+
{"title": "Community", "submenu": [
26+
{"link": "/blog.sql", "title": "Blog"},
27+
{"link": "//github.com/sqlpage/SQLPage", "title": "Github"}
28+
]}
29+
]
30+
}
31+
```
32+
33+
#### Dynamic menu
34+
35+
If your menu depends on the database content, or on special `sqlpage` functions,
36+
you can use the `dynamic` component,
37+
but this time with the [`sqlpage.run_sql`](functions.sql?function=run_sql#function)
38+
function to generate the menu from the database.
39+
40+
```sql
41+
SELECT 'dynamic' AS component, sqlpage.run_sql('shell.sql') AS properties;
42+
```
43+
44+
and in `shell.sql`:
45+
46+
```sql
47+
SELECT 'shell' AS component, 'run_sql is cool' as title,
48+
json_group_array(json_object(
49+
'link', link,
50+
'title', title
51+
)) as menu_item
52+
FROM my_menu_items
53+
```
54+
55+
(check your database documentation for the exact syntax of the `json_group_array` function).
56+
57+
Another case when dynamic menus are useful is when you want to show some
58+
menu items only in certain conditions.
59+
60+
For instance, you could show an "Admin panel" menu item only to users with the "admin" role,
61+
a "Profile" menu item only to authenticated users,
62+
and a "Login" menu item only to unauthenticated users:
63+
64+
```sql
65+
set role = (
66+
SELECT role FROM users
67+
INNER JOIN sessions ON users.id = sessions.user_id
68+
WHERE sessions.session_id = sqlpage.cookie('session_id')
69+
); -- Read more about how to handle user sessions in the "authentication" component documentation
70+
71+
SELECT
72+
'shell' AS component,
73+
'My authenticated website' AS title,
74+
75+
-- Add an admin panel link if the user is an admin
76+
CASE WHEN $role = 'admin' THEN '{"link": "admin.sql", "title": "Admin panel"}' END AS menu_item,
77+
78+
-- Add a profile page if the user is authenticated
79+
CASE WHEN $role IS NOT NULL THEN '{"link": "profile.sql", "title": "My profile"}' END AS menu_item,
80+
81+
-- Add a login link if the user is not authenticated
82+
CASE WHEN $role IS NULL THEN 'login' END AS menu_item
83+
;
84+
```
85+
86+
More about how to handle user sessions in the [authentication component documentation](?component=authentication#component).
87+
88+
### Menu with icons
89+
90+
The "icon" attribute may be specified for items in the top menu and submenus to display an icon
91+
before the title (or instead). Similarly, the "image" attribute defines a file-based icon. For
92+
image-based icons, the "size" attribute may be specified at the top level of menu_item only to
93+
reduce the size of image-based icons. The following snippet provides an example, which is also
94+
available [here](examples/menu_icon.sql).
95+
96+
```sql
97+
SELECT
98+
'shell' AS component,
99+
'SQLPage' AS title,
100+
'database' AS icon,
101+
'/' AS link,
102+
TRUE AS fixed_top_menu,
103+
'{"title":"About","icon": "settings","submenu":[{"link":"/safety.sql","title":"Security","icon": "logout"},{"link":"/performance.sql","title":"Performance"}]}' AS menu_item,
104+
'{"title":"Examples","image": "https://upload.wikimedia.org/wikipedia/en/6/6b/Terrestrial_globe.svg","submenu":[{"link":"/examples/tabs/","title":"Tabs","image": "https://upload.wikimedia.org/wikipedia/en/6/6b/Terrestrial_globe.svg"},{"link":"/examples/layouts.sql","title":"Layouts"}]}' AS menu_item,
105+
'{"title":"Examples","size":"sm","image": "https://upload.wikimedia.org/wikipedia/en/6/6b/Terrestrial_globe.svg","submenu":[{"link":"/examples/tabs/","title":"Tabs","image": "https://upload.wikimedia.org/wikipedia/en/6/6b/Terrestrial_globe.svg"},{"link":"/examples/layouts.sql","title":"Layouts"}]}' AS menu_item,
106+
'Official [SQLPage](https://sql-page.com) documentation' as footer;
107+
```

0 commit comments

Comments
 (0)