From 848651757a059bf42c6f0208905501d16f81ac10 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sat, 10 Apr 2021 01:04:00 +1200 Subject: [PATCH] Autofocus search if user-agent not a mobile device --- api/pages.js | 11 +++++++++++ pug/home.pug | 4 ++-- server.js | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 api/pages.js diff --git a/api/pages.js b/api/pages.js new file mode 100644 index 0000000..191fa40 --- /dev/null +++ b/api/pages.js @@ -0,0 +1,11 @@ +const {render} = require("pinski/plugins") + +module.exports = [ + { + route: "/", methods: ["GET"], code: async ({req}) => { + const userAgent = req.headers["user-agent"] || "" + const mobile = userAgent.toLowerCase().includes("mobile") + return render(200, "pug/home.pug", {mobile}) + } + } +] diff --git a/pug/home.pug b/pug/home.pug index fa6814a..dc9b01f 100644 --- a/pug/home.pug +++ b/pug/home.pug @@ -11,9 +11,9 @@ block content p You're in control. Watch things your way. p Go on. What do you want to watch? form(method="get" action="/search").encouraging-search-form - input(type="text" name="q" placeholder="I'd like to watch..." autocomplete="off").search.base-border-look + input(type="text" name="q" placeholder="I'd like to watch..." autocomplete="off" autofocus=!mobile).search.base-border-look p: a(href="/cant-think") ...can't think of anything? .encouraging-message p CloudTube gets better with your help. I can't deal with issues that I don't know about. - p: a(href="https://todo.sr.ht/~cadence/tube") Report a problem or missing feature \ No newline at end of file + p: a(href="https://todo.sr.ht/~cadence/tube") Report a problem or missing feature diff --git a/server.js b/server.js index 24fcd08..9fb7cb7 100644 --- a/server.js +++ b/server.js @@ -16,7 +16,6 @@ const {setInstance} = require("pinski/plugins") server.addRoute("/static/css/main.css", "sass/main.sass", "sass") server.addPugDir("pug", ["pug/includes"]) - server.addRoute("/", "pug/home.pug", "pug") server.addRoute("/cant-think", "pug/cant-think.pug", "pug") server.addStaticHashTableDir("html/static/js")