Editorial list pages, fixes, general cleanup
Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
parent
ab8cb2a09d
commit
4e9d790b6a
70
meme.scm
70
meme.scm
|
@ -27,8 +27,6 @@
|
|||
#:use-module (ice-9 textual-ports)
|
||||
#:use-module (ice-9 binary-ports))
|
||||
|
||||
(install-suspendable-ports!)
|
||||
|
||||
(define (handler request request-body)
|
||||
(let ((uri (request-uri request))
|
||||
(path (uri-path (request-uri request)))
|
||||
|
@ -52,27 +50,51 @@
|
|||
((equal? path "/proxy")
|
||||
(proxy-page (uri-query uri)))
|
||||
((or (equal? path "/")
|
||||
(equal? (car path-components) "page"))
|
||||
(newsfeed-page path))
|
||||
(equal? (car path-components) "page")
|
||||
(and
|
||||
(equal? (car path-components) "editorials")
|
||||
(or
|
||||
(equal? (length path-components) 1)
|
||||
(pages? path-components "interviews")
|
||||
(pages? path-components "in-the-media")
|
||||
(pages? path-components "white-papers")
|
||||
(pages? path-components "episode-notes")
|
||||
(pages? path-components "behind-the-scenes")
|
||||
(pages? path-components "meme-review")
|
||||
(pages? path-components "collections")
|
||||
(pages? path-components "poll")
|
||||
(pages? path-components "guides")
|
||||
(pages? path-components "meme-insider")
|
||||
(pages? path-components "insights"))))
|
||||
(articles-page path))
|
||||
((or
|
||||
(equal? (car (last-pair path-components)) "photos")
|
||||
(and (>= (length path-components) 3)
|
||||
(equal? (list-ref
|
||||
path-components
|
||||
(- (length path-components) 3))
|
||||
"photos")
|
||||
(equal? (list-ref
|
||||
path-components
|
||||
(- (length path-components) 2))))
|
||||
(and (>= (length path-components) 2)
|
||||
(equal? (list-ref
|
||||
path-components
|
||||
(- (length path-components) 2))
|
||||
"photos")
|
||||
(not (> (string-count
|
||||
(car (last-pair path-components))
|
||||
char-set:digit 0 1)
|
||||
0))))
|
||||
(and (or
|
||||
(and
|
||||
(>= (length path-components) 2)
|
||||
(equal? (list-ref path-components
|
||||
(- (length path-components) 2))
|
||||
"photos")
|
||||
(not (> (string-count (car (last-pair path-components))
|
||||
char-set:digit 0 1) 0)))
|
||||
(and
|
||||
(>= (length path-components) 3)
|
||||
(equal? (list-ref path-components
|
||||
(- (length path-components) 3))
|
||||
"photos"))
|
||||
(and
|
||||
(>= (length path-components) 4)
|
||||
(equal? (list-ref path-components
|
||||
(- (length path-components) 4))
|
||||
"photos")))
|
||||
(or
|
||||
(pages? path-components "trending")
|
||||
(pages? path-components "most-commented")
|
||||
(pages? path-components "most-favorited")
|
||||
(pages? path-components "most-liked")
|
||||
(pages? path-components "least-liked")
|
||||
(pages? path-components "most-viewed")
|
||||
(pages? path-components "templates"))))
|
||||
(photos-page path))
|
||||
((and (>= (length path-components) 2)
|
||||
(equal? (list-ref
|
||||
|
@ -174,10 +196,12 @@
|
|||
(meme-list-page path))
|
||||
(else (error-page 404)))))
|
||||
|
||||
(define sock (socket PF_INET SOCK_STREAM 0))
|
||||
(install-suspendable-ports!)
|
||||
|
||||
(let ((port (if (getenv "PORT")
|
||||
(string->number (getenv "PORT"))
|
||||
8003)))
|
||||
8003))
|
||||
(sock (socket PF_INET SOCK_STREAM 0)))
|
||||
(bind sock AF_INET INADDR_ANY port)
|
||||
(fcntl sock F_SETFL (logior O_NONBLOCK
|
||||
(fcntl sock F_GETFL)))
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#:use-module (system foreign)
|
||||
#:use-module (system foreign-library)
|
||||
#:export (gumbo-libxml-parse
|
||||
xml-doc-get-root-element
|
||||
xml-free-doc
|
||||
xml-node-list-get-string
|
||||
xml-xpath-new-context
|
||||
|
@ -33,14 +32,14 @@
|
|||
next
|
||||
child
|
||||
child1
|
||||
props
|
||||
attrs
|
||||
name
|
||||
doc
|
||||
text
|
||||
nodeset
|
||||
nodeset-nodes
|
||||
floatval
|
||||
strval
|
||||
nodeset-nodes-null?
|
||||
xpath-null?
|
||||
dump-xml
|
||||
get-xpath
|
||||
dump-xpath-xml
|
||||
|
@ -92,11 +91,6 @@
|
|||
(pointer->procedure '*
|
||||
(dynamic-func "gumbo_libxml_parse" gumbo-libxml)
|
||||
(list '*)))
|
||||
(define xml-doc-get-root-element
|
||||
(pointer->procedure '*
|
||||
(dynamic-func "xmlDocGetRootElement" libxml2)
|
||||
(list '*)))
|
||||
|
||||
(define xml-free-doc
|
||||
(pointer->procedure void
|
||||
(dynamic-func "xmlFreeDoc" libxml2)
|
||||
|
@ -113,10 +107,6 @@
|
|||
(pointer->procedure void
|
||||
(dynamic-func "xmlNodeDump" libxml2)
|
||||
(list '* '* '* int int)))
|
||||
(define xml-unlink-node
|
||||
(pointer->procedure void
|
||||
(dynamic-func "xmlUnlinkNode" libxml2)
|
||||
(list '*)))
|
||||
|
||||
(define xml-xpath-new-context
|
||||
(pointer->procedure '*
|
||||
|
@ -126,10 +116,6 @@
|
|||
(pointer->procedure '*
|
||||
(dynamic-func "xmlXPathEvalExpression" libxml2)
|
||||
(list '* '*)))
|
||||
(define xml-xpath-free-object
|
||||
(pointer->procedure void
|
||||
(dynamic-func "xmlXPathFreeObject" libxml2)
|
||||
(list '*)))
|
||||
(define xml-xpath-free-context
|
||||
(pointer->procedure void
|
||||
(dynamic-func "xmlXPathFreeContext" libxml2)
|
||||
|
@ -149,7 +135,7 @@
|
|||
(if (= times 0)
|
||||
(next (child ptr) 0)
|
||||
(child1 (next (child ptr) 0) (- times 1))))
|
||||
(define (props ptr)
|
||||
(define (attrs ptr)
|
||||
(list-ref (parse-c-struct ptr xml-node) 11))
|
||||
(define (name ptr)
|
||||
(pointer->string (caddr (parse-c-struct ptr xml-node))))
|
||||
|
@ -162,10 +148,10 @@
|
|||
(cadr (parse-c-struct ptr xml-xpath-object)))
|
||||
(define (nodeset-nodes ptr)
|
||||
(dereference-pointer (caddr (parse-c-struct ptr xml-nodeset))))
|
||||
(define (floatval ptr)
|
||||
(cadddr (parse-c-struct ptr xml-xpath-object)))
|
||||
(define (strval ptr)
|
||||
(list-ref (parse-c-struct ptr xml-xpath-object) 4))
|
||||
(define (nodeset-nodes-null? ptr)
|
||||
(null-pointer? (caddr (parse-c-struct ptr xml-nodeset))))
|
||||
(define (xpath-null? xpath d)
|
||||
(nodeset-nodes-null? (get-xpath-nodeset xpath d)))
|
||||
|
||||
(define (dump-xml node)
|
||||
(define buffer (xml-buffer-create))
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
#:use-module (web uri)
|
||||
#:use-module (ice-9 receive)
|
||||
#:use-module (system foreign)
|
||||
#:export (error-page
|
||||
newsfeed-page
|
||||
#:export (pages?
|
||||
error-page
|
||||
articles-page
|
||||
meme-page
|
||||
meme-list-page
|
||||
category-list-page
|
||||
|
@ -36,6 +37,11 @@
|
|||
|
||||
(define base-url "https://knowyourmeme.com")
|
||||
|
||||
(define (pages? components str)
|
||||
(or (equal? (car (last-pair components)) str)
|
||||
(and (equal? (list-ref components (- (length components) 2)) "page")
|
||||
(equal? (list-ref components (- (length components) 3)) str))))
|
||||
|
||||
(define good-response
|
||||
(build-response #:code 200
|
||||
#:headers `((content-type . (text/html)))))
|
||||
|
@ -74,9 +80,9 @@
|
|||
(redirect resp (response-code resp)))
|
||||
(else (error-page (response-code resp))))))
|
||||
|
||||
(define (newsfeed-page path)
|
||||
(display ";\tHandler: newsfeed-page")
|
||||
(generic-page newsfeed-template path))
|
||||
(define (articles-page path)
|
||||
(display ";\tHandler: articles-page")
|
||||
(generic-page articles-template path))
|
||||
|
||||
(define (meme-page path)
|
||||
(display ";\tHandler: meme-page")
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#:export (proxy
|
||||
get-leaderboard
|
||||
get-trending
|
||||
get-newsfeed
|
||||
get-articles
|
||||
get-meme
|
||||
get-meme-list
|
||||
get-category-list
|
||||
|
@ -76,7 +76,7 @@
|
|||
((= i
|
||||
(xml-child-element-count
|
||||
(get-xpath-node "//*[@id=\"trending-bar\"]" d) 0))
|
||||
trending)
|
||||
(cdr trending))
|
||||
(append!
|
||||
trending
|
||||
(list
|
||||
|
@ -94,62 +94,45 @@
|
|||
"]/text()")
|
||||
d #f))))))
|
||||
|
||||
(define (get-newsfeed d)
|
||||
(define newsfeed (list ""))
|
||||
(define (get-articles d)
|
||||
(define pref "")
|
||||
(define articles (list ""))
|
||||
(do ((i 1 (1+ i)))
|
||||
((= i 6) newsfeed)
|
||||
((xpath-null?
|
||||
(string-append "/html/body/div[3]/div/div[3]/article["
|
||||
(number->string i)
|
||||
"]") d)
|
||||
(cdr articles))
|
||||
(set! pref (string-append "/html/body/div[3]/div/div[3]/article["
|
||||
(number->string i)
|
||||
"]"))
|
||||
(append!
|
||||
newsfeed
|
||||
articles
|
||||
(list
|
||||
(list
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"/html/body/div[3]/div/div[3]/article["
|
||||
(number->string i)
|
||||
"]/@id")
|
||||
d #t)
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"/html/body/div[3]/div/div[3]/article["
|
||||
(number->string i)
|
||||
"]/div/section/h1/a/@href")
|
||||
d #t)
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"/html/body/div[3]/div/div[3]/article["
|
||||
(number->string i)
|
||||
"]/div/section/h1/a/text()")
|
||||
d #f)
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"/html/body/div[3]/div/div[3]/article["
|
||||
(number->string i)
|
||||
"]//img/@data-src")
|
||||
d #t)
|
||||
(if
|
||||
(equal?
|
||||
(xml-child-element-count
|
||||
(get-xpath-node
|
||||
(string-append
|
||||
"/html/body/div[3]/div/div[3]/article["
|
||||
(number->string i)
|
||||
"]/div/section/div[2]")
|
||||
d)
|
||||
0)
|
||||
0)
|
||||
""
|
||||
(if (not (xpath-null? (string-append pref "/div/section") d))
|
||||
(list
|
||||
(get-xpath-string (string-append pref "/div/section/h1/a/@href")
|
||||
d #t)
|
||||
(get-xpath-string (string-append pref "/div/section/h1/a/text()")
|
||||
d #f)
|
||||
(get-xpath-string (string-append pref "//img/@data-src") d #t)
|
||||
(if
|
||||
(equal?
|
||||
(xml-child-element-count
|
||||
(get-xpath-node (string-append pref "/div/section/div[2]") d)
|
||||
0) 0)
|
||||
""
|
||||
(get-xpath-string
|
||||
(string-append pref "/div/section/div[2]/p/text()") d #f))
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"/html/body/div[3]/div/div[3]/article["
|
||||
(number->string i)
|
||||
"]/div/section/div[2]/p/text()")
|
||||
d #f))
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"/html/body/div[3]/div/div[3]/article["
|
||||
(number->string i)
|
||||
"]/div/section/p[1]/em/text()")
|
||||
d #f))))))
|
||||
(string-append pref "/div/section/p[1]/em/text()") d #f))
|
||||
(list
|
||||
(get-xpath-string (string-append pref "/h1/a/@href") d #t)
|
||||
(get-xpath-string (string-append pref "/h1/a/text()") d #f)
|
||||
(get-xpath-string (string-append pref "//img/@data-src") d #t)
|
||||
(get-xpath-string (string-append pref "/div[2]/p/text()") d #f)
|
||||
(get-xpath-string (string-append pref "/div[3]/em/text()") d #f)
|
||||
))))))
|
||||
|
||||
(define (get-meme d)
|
||||
(define bodycopy
|
||||
|
@ -204,7 +187,7 @@
|
|||
(cond
|
||||
((and (equal? (name chld1) "a")
|
||||
(equal? (name (child chld1)) "img"))
|
||||
(set! chld2 (props (child chld1)))
|
||||
(set! chld2 (attrs (child chld1)))
|
||||
(while (not (null-pointer? chld2))
|
||||
(cond
|
||||
((equal? (name chld2) "data-src")
|
||||
|
@ -226,12 +209,7 @@
|
|||
"/html/body/div[3]/div/article/header/section/h1/text()" d #f)
|
||||
(get-xpath-string
|
||||
"/html/body/div[3]/div/article/header/a/img/@src" d #t)
|
||||
(if (null-pointer?
|
||||
(caddr (parse-c-struct
|
||||
(get-xpath-nodeset
|
||||
"/html/body/div[3]/div/article/header/section/div/h5"
|
||||
d)
|
||||
xml-nodeset)))
|
||||
(if (xpath-null? "/html/body/div[3]/div/article/header/section/div/h5" d)
|
||||
""
|
||||
(dump-xpath-xml
|
||||
"/html/body/div[3]/div/article/header/section/div/h5" d))
|
||||
|
@ -262,7 +240,7 @@
|
|||
(cond ((and (equal? (name chld1) "td")
|
||||
(not (null-pointer? (child1 chld1 0)))
|
||||
(not (equal? (name (child1 chld1 0)) "div")))
|
||||
(set! chld2 (props (child1 chld1 0)))
|
||||
(set! chld2 (attrs (child1 chld1 0)))
|
||||
(while (not (null-pointer? chld2))
|
||||
(cond
|
||||
((equal? (name chld2) "href")
|
||||
|
@ -271,7 +249,7 @@
|
|||
(list (text chld2)))
|
||||
(break)))
|
||||
(set! chld2 (next chld2 0)))
|
||||
(set! chld3 (props (child (child1 chld1 0))))
|
||||
(set! chld3 (attrs (child (child1 chld1 0))))
|
||||
(while (not (null-pointer? chld3))
|
||||
(cond
|
||||
((equal? (name chld3) "data-src")
|
||||
|
@ -290,23 +268,13 @@
|
|||
(append
|
||||
(list
|
||||
(dump-xpath-xml "/html/body/div[3]/div/div[1]/header/hgroup/h1" d)
|
||||
(if (null-pointer?
|
||||
(caddr (parse-c-struct
|
||||
(get-xpath-nodeset
|
||||
"/html/body/div[3]/div/div[1]/header/hgroup/p"
|
||||
d)
|
||||
xml-nodeset)))
|
||||
(if (xpath-null? "/html/body/div[3]/div/div[1]/header/hgroup/p" d)
|
||||
""
|
||||
(get-xpath-string
|
||||
"/html/body/div[3]/div/div[1]/header/hgroup/p/text()"
|
||||
d #f))
|
||||
(dump-xpath-xml "/html/body/div[3]/div/nav/ul" d)
|
||||
(if (null-pointer?
|
||||
(caddr (parse-c-struct
|
||||
(get-xpath-nodeset
|
||||
"/html/body/div[3]/div/div[3]/section/div/p"
|
||||
d)
|
||||
xml-nodeset)))
|
||||
(if (xpath-null "/html/body/div[3]/div/div[3]/section/div/p" d)
|
||||
""
|
||||
(dump-xpath-xml "/html/body/div[3]/div/div[3]/section/div/p" d)))
|
||||
(cdr lst)))
|
||||
|
@ -329,7 +297,7 @@
|
|||
((and (equal? (name chld) "a")
|
||||
(not (null-pointer? (child chld)))
|
||||
(not (equal? (name (child chld)) "i")))
|
||||
(set! chld1 (props chld))
|
||||
(set! chld1 (attrs chld))
|
||||
(while (not (null-pointer? chld1))
|
||||
(cond
|
||||
((equal? (name chld1) "data-category")
|
||||
|
@ -340,7 +308,7 @@
|
|||
(break)))
|
||||
(set! chld1 (next chld1 0)))
|
||||
(set! lst1 (list ""))
|
||||
(set! chld1 (props chld))
|
||||
(set! chld1 (attrs chld))
|
||||
(append! lst1 (list (text (child1 chld 0))))
|
||||
(while (not (null-pointer? chld1))
|
||||
(cond
|
||||
|
@ -381,42 +349,26 @@
|
|||
(while (not (null-pointer? chld))
|
||||
(cond
|
||||
((equal? (name chld) "div")
|
||||
(set! chld1 (props chld))
|
||||
(set! chld1 (attrs chld))
|
||||
(while (not (null-pointer? chld1))
|
||||
(cond
|
||||
((and (equal? (name chld1) "class")
|
||||
(equal?
|
||||
(pointer->string
|
||||
(xml-node-list-get-string
|
||||
(doc chld1)
|
||||
(child chld1)
|
||||
1))
|
||||
(text chld1)
|
||||
"item"))
|
||||
(set! chld2 (child1 chld 0))
|
||||
(set! chld3 (props chld2))
|
||||
(set! chld3 (attrs chld2))
|
||||
(while (not (null-pointer? chld3))
|
||||
(cond
|
||||
((equal? (name chld3) "href")
|
||||
(set-car!
|
||||
pair
|
||||
(pointer->string
|
||||
(xml-node-list-get-string
|
||||
(doc chld3)
|
||||
(child chld3)
|
||||
1)))
|
||||
(set-car! pair (text chld3))
|
||||
(break)))
|
||||
(set! chld3 (next chld3 0)))
|
||||
(set! chld4 (props (child1 chld2 0)))
|
||||
(set! chld4 (attrs (child1 chld2 0)))
|
||||
(while (not (null-pointer? chld4))
|
||||
(cond
|
||||
((equal? (name chld4) "data-src")
|
||||
(set-cdr!
|
||||
pair
|
||||
(pointer->string
|
||||
(xml-node-list-get-string
|
||||
(doc chld4)
|
||||
(child chld4)
|
||||
1)))
|
||||
(set-cdr! pair (text chld4))
|
||||
(break)))
|
||||
(set! chld4 (next chld4 0)))
|
||||
(append!
|
||||
|
@ -425,22 +377,19 @@
|
|||
(cons (car pair)
|
||||
(cdr pair))))))
|
||||
(set! chld1 (next chld1 0)))))
|
||||
(set! chld (next chld 0)))
|
||||
(set! chld (next chld 1)))
|
||||
(append
|
||||
(list
|
||||
(dump-xpath-xml "/html/body/div[3]/div/div[1]/header/hgroup/h1" d)
|
||||
(if (null-pointer?
|
||||
(caddr (parse-c-struct
|
||||
(get-xpath-nodeset
|
||||
"/html/body/div[3]/div/div[1]/header/hgroup/p"
|
||||
d)
|
||||
xml-nodeset)))
|
||||
(if (xpath-null? "/html/body/div[3]/div/div[1]/header/hgroup/p" d)
|
||||
""
|
||||
(get-xpath-string
|
||||
"/html/body/div[3]/div/div[1]/header/hgroup/p/text()"
|
||||
d #f))
|
||||
(dump-xpath-xml "/html/body/div[3]/div/nav/ul" d)
|
||||
(dump-xpath-xml "/html/body/div[3]/div/div[3]/section/div/p" d))
|
||||
(if (xpath-null? "/html/body/div[3]/div/div[3]//p" d)
|
||||
""
|
||||
(dump-xpath-xml "/html/body/div[3]/div/div[3]//p" d)))
|
||||
(cdr lst)))
|
||||
|
||||
(define (get-photo d)
|
||||
|
@ -471,42 +420,25 @@
|
|||
(set! chld1 (child chld))
|
||||
(while (not (null-pointer? chld1))
|
||||
(cond ((equal? (name chld1) "td")
|
||||
(set! chld2 (props (child1 chld1 1)))
|
||||
(set! chld2 (attrs (child1 chld1 1)))
|
||||
(while (not (null-pointer? chld2))
|
||||
(cond
|
||||
((equal? (name chld2) "href")
|
||||
(set-car!
|
||||
pair
|
||||
(pointer->string
|
||||
(xml-node-list-get-string
|
||||
(doc chld2)
|
||||
(child chld2)
|
||||
1)))
|
||||
(set-car! pair (text chld2))
|
||||
(break)))
|
||||
(set! chld2 (next chld2 0)))
|
||||
(set! chld3 (props (child1 chld1 2)))
|
||||
(set! chld3 (attrs (child1 chld1 2)))
|
||||
(while (not (null-pointer? chld3))
|
||||
(cond
|
||||
((equal? (name chld3) "data-tiktok-url")
|
||||
(set-cdr!
|
||||
pair
|
||||
(get-tiktok-thumbnail
|
||||
(pointer->string
|
||||
(xml-node-list-get-string
|
||||
(doc chld3)
|
||||
(child chld3)
|
||||
1))))
|
||||
(set-cdr! pair
|
||||
(get-tiktok-thumbnail
|
||||
(text chld2)))
|
||||
(append! lst (list (cons (car pair)
|
||||
(cdr pair))))
|
||||
(break))
|
||||
((equal? (name chld3) "data-src")
|
||||
(set-cdr!
|
||||
pair
|
||||
(pointer->string
|
||||
(xml-node-list-get-string
|
||||
(doc chld3)
|
||||
(child chld3)
|
||||
1)))
|
||||
(set-cdr! pair (text chld3))
|
||||
(append! lst (list (cons (car pair)
|
||||
(cdr pair))))
|
||||
(break)))
|
||||
|
@ -516,12 +448,7 @@
|
|||
(append
|
||||
(list
|
||||
(dump-xpath-xml "/html/body/div[3]/div/div[1]/header/hgroup/h1" d)
|
||||
(if (null-pointer?
|
||||
(caddr (parse-c-struct
|
||||
(get-xpath-nodeset
|
||||
"/html/body/div[3]/div/div[1]/header/hgroup/p"
|
||||
d)
|
||||
xml-nodeset)))
|
||||
(if (xpath-null? "/html/body/div[3]/div/div[1]/header/hgroup/p" d)
|
||||
""
|
||||
(get-xpath-string
|
||||
"/html/body/div[3]/div/div[1]/header/hgroup/p/text()"
|
||||
|
@ -534,16 +461,12 @@
|
|||
(define gallery (list ""))
|
||||
(define lst (list ""))
|
||||
(define xpath-start "")
|
||||
(do ((i 1 (+ i 2)))
|
||||
((>= i
|
||||
(- (xml-child-element-count
|
||||
(get-xpath-node "/html/body/div[3]/aside" d) 0)
|
||||
1))
|
||||
gallery)
|
||||
(set! lst (list
|
||||
(do ((i 1 (1+ i)))
|
||||
((> i 2) (cdr gallery))
|
||||
(set! lst (list
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"/html/body/div[3]/aside/div["
|
||||
"//*[@id=\"popular_galleries\"]["
|
||||
(number->string i)
|
||||
"]/h3/text()")
|
||||
d #f)))
|
||||
|
@ -552,7 +475,7 @@
|
|||
(do ((k 1 (+ k 1)))
|
||||
((> k 2))
|
||||
(set! xpath-start (string-append
|
||||
"/html/body/div[3]/aside/div[" (number->string i)
|
||||
"//*[@id=\"popular_galleries\"][" (number->string i)
|
||||
"]/table/tbody/tr[" (number->string j) "]/td["
|
||||
(number->string k) "]"))
|
||||
(append!
|
||||
|
@ -568,39 +491,41 @@
|
|||
gallery
|
||||
(list lst))))
|
||||
|
||||
(define (get-sidebar-trending d)
|
||||
(define lst (list
|
||||
(get-xpath-string "/html/body/div[3]/aside/div[4]/h3/a/@href" d #t)
|
||||
(get-xpath-string "/html/body/div[3]/aside/div[4]/h3/a/text()" d #f)))
|
||||
(do ((i 1 (1+ i)))
|
||||
((> i 3))
|
||||
(do ((j 1 (1+ j)))
|
||||
((> j 3))
|
||||
(append!
|
||||
(define (get-sidebar-trending d)
|
||||
(define lst '())
|
||||
(cond
|
||||
((null-pointer? (get-xpath-node "//*[@id=\"trending_photos\"]" d)) "")
|
||||
(else
|
||||
(set!
|
||||
lst
|
||||
(list
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"/html/body/div[3]/aside/div[4]/table/tbody/tr["
|
||||
(number->string i)
|
||||
"]/td[" (number->string j) "]/a/@href")
|
||||
d #t)
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"/html/body/div[3]/aside/div[4]/table/tbody/tr["
|
||||
(number->string i)
|
||||
"]/td[" (number->string j) "]/a/img/@data-src")
|
||||
d #t)))))
|
||||
lst)
|
||||
(get-xpath-string "//*[@id=\"trending_photos\"]/h3/a/@href" d #t)
|
||||
(get-xpath-string "//*[@id=\"trending_photos\"]/h3/a/text()" d #f)))
|
||||
(do ((i 1 (1+ i)))
|
||||
((> i 3))
|
||||
(do ((j 1 (1+ j)))
|
||||
((> j 3))
|
||||
(append!
|
||||
lst
|
||||
(list
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"//*[@id=\"trending_photos\"]/table/tbody/tr["
|
||||
(number->string i)
|
||||
"]/td[" (number->string j) "]/a/@href")
|
||||
d #t)
|
||||
(get-xpath-string
|
||||
(string-append
|
||||
"//*[@id=\"trending_photos\"]/table/tbody/tr["
|
||||
(number->string i)
|
||||
"]/td[" (number->string j) "]/a/img/@data-src")
|
||||
d #t)))))
|
||||
lst)))
|
||||
|
||||
(define (get-pagination d)
|
||||
(if (null-pointer?
|
||||
(dereference-pointer
|
||||
(caddr
|
||||
(parse-c-struct
|
||||
(get-xpath-nodeset
|
||||
"//div[@class=\"pagination\"]"
|
||||
d)
|
||||
xml-nodeset))))
|
||||
""
|
||||
(dump-xpath-xml "//div[@class=\"pagination\"]" d)))
|
||||
(get-xpath-node
|
||||
"//*[@class=\"pagination\"]"
|
||||
d))
|
||||
""
|
||||
(dump-xpath-xml "//*[@class=\"pagination\"]" d)))
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#:use-module (ice-9 string-fun)
|
||||
#:use-module (system foreign)
|
||||
#:export (error-template
|
||||
newsfeed-template
|
||||
articles-template
|
||||
meme-template
|
||||
meme-list-template
|
||||
category-list-template
|
||||
|
@ -158,18 +158,18 @@
|
|||
`(p (a (@ (href ,(kym->local (car l))))
|
||||
,(html->shtml (cadr l))))
|
||||
`()))
|
||||
(cdr trending))))
|
||||
trending)))
|
||||
|
||||
(define (newsfeed->sxml newsfeed)
|
||||
(define (articles->sxml articles)
|
||||
`(,(map (lambda (l)
|
||||
`(div (@ (class "articles box"))
|
||||
(a (@ (href ,(kym->local (cadr l))))
|
||||
(h1 ,(caddr l))
|
||||
(img (@ (src ,(proxy (cadddr l)))
|
||||
(alt ,(caddr l))))
|
||||
(p ,(list-ref l 4))
|
||||
(i ,(list-ref l 5)))))
|
||||
(cdr newsfeed))))
|
||||
(a (@ (href ,(kym->local (car l))))
|
||||
(h1 ,(cadr l))
|
||||
(img (@ (src ,(proxy (caddr l)))
|
||||
(alt ,(cadr l))))
|
||||
(p ,(cadddr l))
|
||||
(i ,(list-ref l 4)))))
|
||||
articles)))
|
||||
|
||||
(define (meme->sxml meme)
|
||||
`(div
|
||||
|
@ -252,7 +252,7 @@
|
|||
(p "Source: " ,(html->shtml (cadddr photo))))
|
||||
(div (@ (class "box photo-body"))
|
||||
(a (@ (href ,(string-replace-substring
|
||||
(caddr photo) "newsfeed" "original"))
|
||||
(caddr photo) "articles" "original"))
|
||||
(target "_blank"))
|
||||
(img (@ (alt ,(cadr photo))
|
||||
(src ,(caddr photo))))))))
|
||||
|
@ -300,58 +300,61 @@
|
|||
(list-ref l 15)))
|
||||
(alt ,(list-ref l 14))))
|
||||
(p (b ,(list-ref l 16)))))))))
|
||||
(cdr sidebar-gallery)))
|
||||
sidebar-gallery))
|
||||
|
||||
(define (sidebar-trending->sxml sidebar-trending)
|
||||
`(div (@ (class "sidebar box"))
|
||||
(h3 (a (@ (href ,(kym->local (car sidebar-trending))))
|
||||
,(cadr sidebar-trending)))
|
||||
(table (@ (class "trending-images"))
|
||||
(tr (td (a (@ (href ,(kym->local (caddr sidebar-trending))))
|
||||
(img (@ (src ,(proxy (cadddr sidebar-trending)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 4))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 5)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 6))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 7))))))))
|
||||
(tr (td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 8))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 9)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 10))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 11)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 12))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(car
|
||||
(list-tail sidebar-trending 13)))))))))
|
||||
(tr (td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 14))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 15)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 16))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 17)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 18))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(car
|
||||
(list-tail sidebar-trending
|
||||
19))))))))))))
|
||||
(if (not (equal? sidebar-trending ""))
|
||||
`(div (@ (class "sidebar box"))
|
||||
(h3 (a (@ (href ,(kym->local (car sidebar-trending))))
|
||||
,(cadr sidebar-trending)))
|
||||
(table (@ (class "trending-images"))
|
||||
(tr (td (a (@ (href ,(kym->local (caddr sidebar-trending))))
|
||||
(img (@ (src ,(proxy (cadddr sidebar-trending)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 4))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 5)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 6))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 7))))))))
|
||||
(tr (td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 8))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 9)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 10))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 11)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 12))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(car
|
||||
(list-tail sidebar-trending
|
||||
13)))))))))
|
||||
(tr (td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 14))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 15)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 16))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(list-ref sidebar-trending 17)))))))
|
||||
(td (a (@ (href
|
||||
,(kym->local (list-ref sidebar-trending 18))))
|
||||
(img (@ (src
|
||||
,(proxy
|
||||
(car
|
||||
(list-tail sidebar-trending
|
||||
19)))))))))))
|
||||
`()))
|
||||
|
||||
(define (pagination->sxml pagination)
|
||||
(if (not (equal? pagination ""))
|
||||
|
@ -370,7 +373,7 @@
|
|||
(h1 (@ (class "error")) ,(number->string code)))
|
||||
,footer))))
|
||||
|
||||
(define (newsfeed-template body)
|
||||
(define (articles-template body)
|
||||
(shtml->html
|
||||
`(html ,(html-head "MeMe")
|
||||
(body
|
||||
|
@ -378,7 +381,7 @@
|
|||
,(leaderboard->sxml (get-leaderboard body))
|
||||
,(trending->sxml (get-trending body))
|
||||
(div (@ (class "left"))
|
||||
,(newsfeed->sxml (get-newsfeed body))
|
||||
,(articles->sxml (get-articles body))
|
||||
,(pagination->sxml (get-pagination body)))
|
||||
(div (@ (class "right"))
|
||||
,(sidebar-gallery->sxml (get-sidebar-gallery body))
|
||||
|
|
|
@ -287,11 +287,23 @@ ul.meme-list-list a:hover p.tooltip {
|
|||
}
|
||||
|
||||
.category-list.box ul {
|
||||
column-count: 3;
|
||||
display: inline-flex;
|
||||
flex-wrap: wrap;
|
||||
flex-grow: 0;
|
||||
flex-shrink: 0;
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
.category-list.box ul li {
|
||||
width: 30%;
|
||||
}
|
||||
.category-list.box ul li ul {
|
||||
column-count: 1;
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.category-list.box ul li ul li {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.photos.box ul li ul,
|
||||
|
|
Loading…
Reference in New Issue