From 5d5045de54b193110d58d63554ce7da6feffca30 Mon Sep 17 00:00:00 2001 From: HChenZi Date: Tue, 4 Apr 2023 12:22:37 +0800 Subject: [PATCH 1/2] feat: Get url from req for index page --- index.js | 3 ++- views/index.pug | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 641348b..72c41e6 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,8 @@ app.use(compression()) app.set('view engine', 'pug') app.get('/', (req, res) => { - res.render('index') + const url = req.protocol+'://'+req.get('host') + res.render('index', { url }) }); // get the image diff --git a/views/index.pug b/views/index.pug index 4f681d3..b77784a 100644 --- a/views/index.pug +++ b/views/index.pug @@ -25,16 +25,16 @@ html h3 How to use: h5 SVG address - code https://count.getloli.com/get/@:name + code #{url}/get/@:name h5 Img tag - code <img src="https://count.getloli.com/get/@:name" alt=":name" /> + code <img src="#{url}/get/@:name" alt=":name" /> h5 Markdown - code ![:name](https://count.getloli.com/get/@:name) + code ![:name](#{url}/get/@:name) h3 eg: - Moe Count! + Moe Count! i Data can access by anyone, please | DO NOT @@ -43,19 +43,19 @@ html details summary(style='display: inline-block;', onclick='_evt_push("click", "normal", "more_theme")') h3(style='display: inline-block; cursor: pointer;') More theme - p(style='margin: 0;') Just use the query parameters theme, like this: https://count.getloli.com/get/@:name?theme=moebooru + p(style='margin: 0;') Just use the query parameters theme, like this: #{url}/get/@:name?theme=moebooru h5 asoul - img(src='https://count.getloli.com/get/@demo?theme=asoul', alt='A-SOUL') + img(src='#{url}/get/@demo?theme=asoul', alt='A-SOUL') h5 moebooru - img(src='https://count.getloli.com/get/@demo?theme=moebooru', alt='Moebooru') + img(src='#{url}/get/@demo?theme=moebooru', alt='Moebooru') h5 moebooru-h - img(src='https://count.getloli.com/get/@demo?theme=moebooru-h', alt='Moebooru-Hentai') + img(src='#{url}/get/@demo?theme=moebooru-h', alt='Moebooru-Hentai') h5 rule34 - img(src='https://count.getloli.com/get/@demo?theme=rule34', alt='Rule34') + img(src='#{url}/get/@demo?theme=rule34', alt='Rule34') h5 gelbooru - img(src='https://count.getloli.com/get/@demo?theme=gelbooru', alt='Gelbooru') + img(src='#{url}/get/@demo?theme=gelbooru', alt='Gelbooru') h5 gelbooru-h - img(src='https://count.getloli.com/get/@demo?theme=gelbooru-h', alt='Gelbooru-Hentai') + img(src='#{url}/get/@demo?theme=gelbooru-h', alt='Gelbooru-Hentai') h3 Credits ul @@ -76,7 +76,7 @@ html h3 Tool .tool - code https://count.getloli.com/get/@ + code #{url}/get/@ input#name(type='text', placeholder=':name', style='display: inline-block; width: 80px; height: 1.4em; line-height: 1.4em; margin: 0 4px; vertical-align: middle;') code ?theme= select#theme(style='display: inline-block; height: 1.6em; line-height: 1.6em; font-size: 14px; margin: 0 4px; padding: 0 4px; vertical-align: middle;') @@ -103,10 +103,10 @@ html return } - img.src = 'https://count.getloli.com/get/@' + text + '?theme=' + theme + img.src = '#{url}/get/@' + text + '?theme=' + theme }) iframe(src="https://chat.getloli.com/room/@Moe-counter?title=%E8%90%8C%E8%90%8C%E8%AE%A1%E6%95%B0%E5%99%A8%E7%9A%84%E7%95%99%E8%A8%80%E6%9D%BF", scrolling="no", frameborder="0", height="70%", width="26%", style="position: fixed;top: 2%;right: 5%;") p.copy - a(href='https://github.com/journey-ad/Moe-Counter', target='_blank', onclick='_evt_push("click", "normal", "go_github")') source code \ No newline at end of file + a(href='https://github.com/journey-ad/Moe-Counter', target='_blank', onclick='_evt_push("click", "normal", "go_github")') source code -- 2.45.2 From 8e3a196dc36b1e5223d8bffead951d65538b8775 Mon Sep 17 00:00:00 2001 From: journey-ad Date: Tue, 4 Apr 2023 15:01:50 +0800 Subject: [PATCH 2/2] perf: Use more precise variable naming and support configuration. --- Readme.md | 1 + config.yml | 1 + index.js | 4 ++-- views/index.pug | 26 +++++++++++++------------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Readme.md b/Readme.md index 9cd1fc3..d5bfd2d 100644 --- a/Readme.md +++ b/Readme.md @@ -48,6 +48,7 @@ $ yarn start ```yaml app: + # site: https://count.getloli.com # your website port: 3000 db: diff --git a/config.yml b/config.yml index 6e6bc78..a5070f3 100644 --- a/config.yml +++ b/config.yml @@ -1,4 +1,5 @@ app: + # site: https://count.getloli.com # your website port: 3000 db: diff --git a/index.js b/index.js index 72c41e6..77237b8 100644 --- a/index.js +++ b/index.js @@ -17,8 +17,8 @@ app.use(compression()) app.set('view engine', 'pug') app.get('/', (req, res) => { - const url = req.protocol+'://'+req.get('host') - res.render('index', { url }) + const site = config.app.site || `${req.protocol}://${req.get('host')}` + res.render('index', { site }) }); // get the image diff --git a/views/index.pug b/views/index.pug index b77784a..a144569 100644 --- a/views/index.pug +++ b/views/index.pug @@ -25,16 +25,16 @@ html h3 How to use: h5 SVG address - code #{url}/get/@:name + code #{site}/get/@:name h5 Img tag - code <img src="#{url}/get/@:name" alt=":name" /> + code <img src="#{site}/get/@:name" alt=":name" /> h5 Markdown - code ![:name](#{url}/get/@:name) + code ![:name](#{site}/get/@:name) h3 eg: - Moe Count! + Moe Count! i Data can access by anyone, please | DO NOT @@ -43,19 +43,19 @@ html details summary(style='display: inline-block;', onclick='_evt_push("click", "normal", "more_theme")') h3(style='display: inline-block; cursor: pointer;') More theme - p(style='margin: 0;') Just use the query parameters theme, like this: #{url}/get/@:name?theme=moebooru + p(style='margin: 0;') Just use the query parameters theme, like this: #{site}/get/@:name?theme=moebooru h5 asoul - img(src='#{url}/get/@demo?theme=asoul', alt='A-SOUL') + img(src='#{site}/get/@demo?theme=asoul', alt='A-SOUL') h5 moebooru - img(src='#{url}/get/@demo?theme=moebooru', alt='Moebooru') + img(src='#{site}/get/@demo?theme=moebooru', alt='Moebooru') h5 moebooru-h - img(src='#{url}/get/@demo?theme=moebooru-h', alt='Moebooru-Hentai') + img(src='#{site}/get/@demo?theme=moebooru-h', alt='Moebooru-Hentai') h5 rule34 - img(src='#{url}/get/@demo?theme=rule34', alt='Rule34') + img(src='#{site}/get/@demo?theme=rule34', alt='Rule34') h5 gelbooru - img(src='#{url}/get/@demo?theme=gelbooru', alt='Gelbooru') + img(src='#{site}/get/@demo?theme=gelbooru', alt='Gelbooru') h5 gelbooru-h - img(src='#{url}/get/@demo?theme=gelbooru-h', alt='Gelbooru-Hentai') + img(src='#{site}/get/@demo?theme=gelbooru-h', alt='Gelbooru-Hentai') h3 Credits ul @@ -76,7 +76,7 @@ html h3 Tool .tool - code #{url}/get/@ + code #{site}/get/@ input#name(type='text', placeholder=':name', style='display: inline-block; width: 80px; height: 1.4em; line-height: 1.4em; margin: 0 4px; vertical-align: middle;') code ?theme= select#theme(style='display: inline-block; height: 1.6em; line-height: 1.6em; font-size: 14px; margin: 0 4px; padding: 0 4px; vertical-align: middle;') @@ -103,7 +103,7 @@ html return } - img.src = '#{url}/get/@' + text + '?theme=' + theme + img.src = '#{site}/get/@' + text + '?theme=' + theme }) iframe(src="https://chat.getloli.com/room/@Moe-counter?title=%E8%90%8C%E8%90%8C%E8%AE%A1%E6%95%B0%E5%99%A8%E7%9A%84%E7%95%99%E8%A8%80%E6%9D%BF", scrolling="no", frameborder="0", height="70%", width="26%", style="position: fixed;top: 2%;right: 5%;") -- 2.45.2