diff --git a/dist/static/layout.css b/dist/static/layout.css index 0e2e28f..18eb684 100644 --- a/dist/static/layout.css +++ b/dist/static/layout.css @@ -300,6 +300,17 @@ body.stats { } } +body.inspire { + height: 100%; + display: grid; + +} +.inspire-entry { + margin: 2rem 0; + width: var(--width-max-content); + box-shadow: -.5rem 0 0 1px var(--color-background), calc(-.5rem - 3px) 0 0 0 +} + .jump-nav { position: sticky; top: 0; diff --git a/functions/about/index.js b/functions/about/index.js index fcad243..7a161d7 100644 --- a/functions/about/index.js +++ b/functions/about/index.js @@ -2,7 +2,7 @@ import Mustache from 'mustache'; import template from './template.html'; import { getDefaultViewData } from '../../lib/view.js'; import {emitPageView} from '../../lib/plausible.js'; -import {renderHtml} from "../../lib/sso-render.js"; +import {renderHtml} from '../../lib/sso-render.js'; export const onRequestGet = async (context) => { emitPageView(context); diff --git a/functions/index.js b/functions/index.js index 6392b33..ad11248 100644 --- a/functions/index.js +++ b/functions/index.js @@ -82,6 +82,7 @@ export const onRequestGet = async (context) => { title: 'kukei.eu', results, hasQuery, + noQuery: !hasQuery, mainClass, noResults: !hasResults, hasResults, diff --git a/functions/inspire/index.js b/functions/inspire/index.js new file mode 100644 index 0000000..71aedf9 --- /dev/null +++ b/functions/inspire/index.js @@ -0,0 +1,29 @@ +import Mustache from 'mustache'; +import template from './template.html'; +import { getDefaultViewData } from '../../lib/view.js'; +import {emitPageView} from '../../lib/plausible.js'; +import {renderHtml} from '../../lib/sso-render.js'; +import {getRandomBlog} from "../../lib/search.js"; + +export const onRequestGet = async (context) => { + emitPageView(context); + const { env } = context; + + const entry = await getRandomBlog(env); + + console.log(entry); + const viewDefaults = await getDefaultViewData(env); + const view = { + ...viewDefaults, + mainClass: 'body inspire', + title: 'About kukei.eu', + entries: [entry], + }; + const html = await renderHtml(template, view); + + return new Response(html, { + headers: { + 'content-type': 'text/html', + }, + }); +}; diff --git a/functions/inspire/template.html b/functions/inspire/template.html new file mode 100644 index 0000000..3bb292c --- /dev/null +++ b/functions/inspire/template.html @@ -0,0 +1,18 @@ +{{{ before }}} +
+

Kukei.eu
get inspired

+

Every page load shows one random blog link.
Have fun! Be inspired!

+
+ {{#entries}} +

{{ title }}

+ {{#excerpt}} +

{{ excerpt }}

+ {{/excerpt}} + {{#excerptSafe}} +

{{{ excerptSafe }}}

+ {{/excerptSafe}} + {{ url }} + {{/entries}} +
+
+{{{ after }}} diff --git a/functions/status/index.js b/functions/status/index.js index fcfb10f..2a3f069 100644 --- a/functions/status/index.js +++ b/functions/status/index.js @@ -2,7 +2,7 @@ import template from './template.html'; import { getDefaultViewData } from '../../lib/view.js'; import {emitPageView} from '../../lib/plausible.js'; import {getUnchecked, getIndexStats, getCrawlHistory} from '../../lib/mongo.js'; -import {renderHtml} from "../../lib/sso-render.js"; +import {renderHtml} from '../../lib/sso-render.js'; export const onRequestGet = async (context) => { emitPageView(context); diff --git a/functions/template.html b/functions/template.html index acce75e..0aea83d 100644 --- a/functions/template.html +++ b/functions/template.html @@ -11,6 +11,9 @@

+ {{#noQuery}} +

or get inspired

+ {{/noQuery}} {{#hasQuery}}

Results generated in {{ doneIn }}ms

diff --git a/lib/search.js b/lib/search.js index c2a71f6..e0552ec 100644 --- a/lib/search.js +++ b/lib/search.js @@ -158,3 +158,16 @@ export const getFacets = async (env) => { lang, }; }; + +export const getRandomBlog = async (env) => { + const client = await getMeiliClient(env); + const { numberOfDocuments: blogPages} = await getMeiliClient(env).index('kukei-blogs').getStats(); + // Random offset between 0 and blogPages + const offset = Math.floor(Math.random() * blogPages); + const { results } = await client.index('kukei-blogs').getDocuments({ + offset, + limit: 1, + }); + + return results?.[0] ?? null; +};