Skip to content

Commit

Permalink
Add site endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed Nov 18, 2023
1 parent 1acba02 commit a309b8a
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Add expand catalog option to get content call @robgietema
- Add content events @robgietema
- Add profile metadata @robgietema
- Add @site endpoint @robgietema

### Bugfix

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/content/get_notfound.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ HTTP/1.1 404 Not Found
Content-Type: application/json

{
"error": "Not found."
"error": "Not found: /random"
}
5 changes: 5 additions & 0 deletions docs/examples/controlpanels/list.res
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ Content-Type: application/json
"@id": "http://localhost:8000/@controlpanels/navigation",
"group": "General",
"title": "Navigation"
},
{
"@id": "http://localhost:8000/@controlpanels/site",
"group": "General",
"title": "Site"
}
]
2 changes: 2 additions & 0 deletions docs/examples/site/get.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GET /@site HTTP/1.1
Accept: application/json
9 changes: 9 additions & 0 deletions docs/examples/site/get.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"@id": "http://localhost:8000/@site",
"robots_txt": "Sitemap: {portal_url}/sitemap.xml.gz\n\n# Define access-restrictions for robots/spiders\n# http://www.robotstxt.org/wc/norobots.html\n\n\n\n# By default we allow robots to access all areas of our site\n# already accessible to anonymous users\n\nUser-agent: *\nDisallow:\n\n\n\n# Add Googlebot-specific syntax extension to exclude forms\n# that are repeated for each piece of content in the site\n# the wildcard is only supported by Googlebot\n# http://www.google.com/support/webmasters/bin/answer.py?answer=40367&ctx=sibling\n\nUser-Agent: Googlebot\nDisallow: /*?\nDisallow: /*atct_album_view$\nDisallow: /*folder_factories$\nDisallow: /*folder_summary_view$\nDisallow: /*login_form$\nDisallow: /*mail_password_form$\nDisallow: /@@search\nDisallow: /*search_rss$\nDisallow: /*sendto_form$\nDisallow: /*summary_view$\nDisallow: /*thumbnail_view$\nDisallow: /*view$\n",
"site_logo": null,
"site_title": "Nick"
}
20 changes: 20 additions & 0 deletions docs/site.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
nav_order: 24
permalink: /site
---

# Site

The `@site` endpoint provides general site-wide information, such as the site title, logo, and other information. It uses the view permission, which requires appropriate authorization.

Send a `GET` request to the `@site` endpoint:

```
{% include_relative examples/site/get.req %}
```

The response will contain the site information:

```
{% include_relative examples/site/get.res %}
```
40 changes: 40 additions & 0 deletions src/profiles/core/controlpanels/site.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"id": "site",
"title:i18n": "Site",
"group": "General",
"schema": {
"fieldsets": [
{
"fields": ["robots_txt", "site_logo", "site_title"],
"id": "general",
"title": "General"
}
],
"properties": {
"robots_txt": {
"title:i18n": "Robots.txt",
"description:i18n": "This is the contents of the robots.txt file.",
"type": "string",
"widget": "textarea"
},
"site_logo": {
"description:i18n": "This shows a custom logo on your site.",
"title:i18n": "Site Logo",
"type": "object",
"widget": "file",
"factory": "Image"
},
"site_title": {
"title:i18n": "Site title",
"description:i18n": "This shows up in the title bar of browsers and in syndication feeds.",
"type": "string"
}
},
"required": []
},
"data": {
"robots_txt": "Sitemap: {portal_url}/sitemap.xml.gz\n\n# Define access-restrictions for robots/spiders\n# http://www.robotstxt.org/wc/norobots.html\n\n\n\n# By default we allow robots to access all areas of our site\n# already accessible to anonymous users\n\nUser-agent: *\nDisallow:\n\n\n\n# Add Googlebot-specific syntax extension to exclude forms\n# that are repeated for each piece of content in the site\n# the wildcard is only supported by Googlebot\n# http://www.google.com/support/webmasters/bin/answer.py?answer=40367&ctx=sibling\n\nUser-Agent: Googlebot\nDisallow: /*?\nDisallow: /*atct_album_view$\nDisallow: /*folder_factories$\nDisallow: /*folder_summary_view$\nDisallow: /*login_form$\nDisallow: /*mail_password_form$\nDisallow: /@@search\nDisallow: /*search_rss$\nDisallow: /*sendto_form$\nDisallow: /*summary_view$\nDisallow: /*thumbnail_view$\nDisallow: /*view$\n",
"site_logo": null,
"site_title": "Nick"
}
}
2 changes: 2 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import querystring from './querystring/querystring';
import roles from './roles/roles';
import search from './search/search';
import sharing from './sharing/sharing';
import site from './site/site';
import system from './system/system';
import types from './types/types';
import users from './users/users';
Expand All @@ -39,6 +40,7 @@ export default [
...roles,
...search,
...sharing,
...site,
...system,
...types,
...users,
Expand Down
29 changes: 29 additions & 0 deletions src/routes/site/site.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Site route.
* @module routes/site/site
*/

import { Controlpanel } from '../../models';
import { getRootUrl } from '../../helpers';

export default [
{
op: 'get',
view: '/@site',
permission: 'View',
handler: async (req, trx) => {
const controlpanel = await Controlpanel.fetchById('site');
const config = controlpanel.data;

// Return database information
return {
json: {
'@id': `${getRootUrl(req)}/@site`,
robots_txt: config?.robots_txt,
site_logo: config?.site_logo,
site_title: config?.site_title,
},
};
},
},
];
6 changes: 6 additions & 0 deletions src/routes/site/site.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import app from '../../app';
import { testRequest } from '../../helpers';

describe('Site', () => {
it('should get the site information', () => testRequest(app, 'site/get'));
});

0 comments on commit a309b8a

Please sign in to comment.