Allow minimising independent wiki notice

This commit is contained in:
Cadence Ember 2024-07-01 02:28:17 +12:00
parent 5672f46886
commit 1ef184547b
3 changed files with 47 additions and 13 deletions

View file

@ -68,9 +68,6 @@
`(p ,(format "This instance is run by the ~a developer, " (config-get 'application_name))
(a (@ (href "https://cadence.moe/contact"))
"Cadence")
". Proudly hosted by "
(a (@ (href "http://alphamethyl.barr0w.net"))
"Barrow Network Solutions" (sup "XD"))
".")
`(p
,(format "This unofficial instance is based off the ~a source code, but is not controlled by the code developer." (config-get 'application_name)))))
@ -88,11 +85,13 @@
;; generate a notice with a link if a fandom wiki has a replacement as part of NIWA or similar
;; if the wiki has no replacement, display nothing
(define (extwiki-notice wikiname title)
(define (extwiki-notice wikiname title req user-cookies)
(define xt (findf (λ (item) (member wikiname (extwiki^-wikinames item))) extwikis))
(cond/var
[xt
(let* ([group (hash-ref extwiki-groups (extwiki^-group xt))]
(let* ([seen? (member wikiname (user-cookies^-notices user-cookies))]
[aside-class (if seen? "niwa__notice niwa--seen" "niwa__notice")]
[group (hash-ref extwiki-groups (extwiki^-group xt))]
[search-page (format "/Special:Search?~a"
(params->query `(("search" . ,title)
("go" . "Go"))))]
@ -103,7 +102,7 @@
[props (extwiki-props^ go)])
(cond
[(eq? (extwiki^-banner xt) 'default)
`(aside (@ (class "niwa__notice"))
`(aside (@ (class ,aside-class))
(h1 (@ (class "niwa__header")) ,(extwiki^-name xt) " has its own website separate from Fandom.")
(a (@ (class "niwa__go") (href ,go)) "Read " ,title " on " ,(extwiki^-name xt) "")
(div (@ (class "niwa__cols"))
@ -117,7 +116,10 @@
`(,@(for/list ([link (extwiki-group^-links group)])
`(a (@ (href ,(cdr link))) ,(car link)))
"This notice is from BreezeWiki"
(a (@ (href "https://docs.breezewiki.com/Reporting_Bugs.html")) "Feedback?"))
(a (@ (rel "nofollow")
(class "niwa__got-it")
(href ,(user-cookies-setter-url/add-notice req user-cookies wikiname)))
"OK, got it"))
" / ")))
(div (@ (class "niwa__right"))
(img (@ (class "niwa__logo") (src ,(extwiki^-logo xt)))))))]
@ -225,7 +227,7 @@
(div (@ (class "fandom-community-header__background tileHorizontally header")))
(div (@ (class "page"))
(main (@ (class "page__main"))
,(extwiki-notice wikiname title)
,(extwiki-notice wikiname title req user-cookies)
(div (@ (class "custom-top"))
(h1 (@ (class "page-title")) ,title)
(nav (@ (class "sitesearch"))

View file

@ -1,6 +1,7 @@
#lang racket/base
(require racket/list
racket/match
racket/string
web-server/http/request-structs
net/url-string
(only-in net/cookies/server cookie-header->alist cookie->set-cookie-header make-cookie)
@ -27,7 +28,8 @@
user-cookies-getter
user-cookies-default
user-cookies-setter
user-cookies-setter-url)
user-cookies-setter-url
user-cookies-setter-url/add-notice)
(struct siteinfo^ (sitename basepage license) #:transparent)
(struct license^ (text url) #:transparent)
@ -90,8 +92,8 @@
;; then no matter what, return the best information we have so far
this-data))
(struct user-cookies^ (theme) #:prefab)
(define user-cookies-default (user-cookies^ 'default))
(struct user-cookies^ (theme notices) #:prefab)
(define user-cookies-default (user-cookies^ 'default '()))
(define (user-cookies-getter req)
(define cookie-header (headers-assq* #"cookie" (request-headers/raw req)))
(define cookies-alist (if cookie-header (cookie-header->alist (header-value cookie-header) bytes->string/utf-8) null))
@ -100,16 +102,29 @@
(match pair
[(cons "theme" (and theme (or "light" "dark" "default")))
(values 'theme (string->symbol theme))]
[(cons "notices" notices)
(values 'notices (string-split notices "|"))]
[_ (values #f #f)])))
(user-cookies^
(hash-ref cookies-hash 'theme (user-cookies^-theme user-cookies-default))))
(hash-ref cookies-hash 'theme (user-cookies^-theme user-cookies-default))
(hash-ref cookies-hash 'notices (user-cookies^-notices user-cookies-default))))
(define (user-cookies-setter user-cookies)
(map (λ (c) (header #"Set-Cookie" (cookie->set-cookie-header c)))
(list (make-cookie "theme" (symbol->string (user-cookies^-theme user-cookies))
#:path "/"
#:max-age (* 60 60 24 365 10))
(make-cookie "notices" (string-join (user-cookies^-notices user-cookies) "|")
#:path "/"
#:max-age (* 60 60 24 365 10)))))
(define (user-cookies-setter-url req new-settings)
(format "/set-user-settings?~a" (params->query `(("next_location" . ,(url->string (request-uri req)))
("new_settings" . ,(format "~a" new-settings))))))
("new_settings" . ,(format "~s" new-settings))))))
(define (user-cookies-setter-url/add-notice req user-cookies notice-name)
(user-cookies-setter-url
req
(struct-copy user-cookies^ user-cookies
[notices (cons notice-name (user-cookies^-notices user-cookies))])))

View file

@ -431,6 +431,23 @@ a.ext-audiobutton { /* see hearthstone/wiki/Diablo_(Duels_hero) */
font-size: 14px;
text-align: right;
}
/* more compact notice after it's been seen the first time */
.niwa--seen {
padding: 1.5vw 2vw 2vw;
overflow-y: auto;
max-height: min(280px, 33vh);
font-size: 17px;
}
.niwa--seen .niwa__header {
font-size: 26px;
}
.niwa--seen .niwa__go {
padding: 10px 18px;
font-size: 20px;
}
.niwa--seen .niwa__got-it {
display: none;
}
/* media queries */