Created
October 19, 2022 22:38
-
-
Save gabrielhidasy/41f425aad16a2cf1f28e88f036b29e71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun hnreader--print-frontpage-item (thing subtext) | |
"Print THING dom and SUBTEXT dom." | |
(let* ((url (format "https://news.ycombinator.com/item?id=%s" (dom-attr thing 'id))) | |
(a-node (dom-child-by-tag (dom-by-class thing "^titleline$") 'a)) | |
(title-link (dom-attr a-node 'href))) | |
(insert (format "\n* %s %s (%s) [%s]\n" | |
;; rank | |
(dom-text (dom-by-class thing "^rank$")) | |
;; title | |
(dom-text a-node) | |
;; points | |
(dom-text (dom-by-class subtext "^score$")) | |
;; comments | |
(dom-text (last (dom-by-tag subtext 'a))))) | |
;; (setq thanh subtext) | |
;; link | |
(insert (format "%s\n[[eww:%s][view story in eww]]\n" title-link title-link)) | |
;; comment link | |
(insert (format "[[elisp:(hnreader-comment \"%s\")][%s]]\n" | |
url | |
url)) | |
;; comment link on external browser | |
(insert (format "[[%s][%s]]\n" url "View comments in browser")) | |
(insert (format "[[eww:%s][%s]]" url "View comments in eww")))) | |
(defun hnreader--print-comments (dom url) | |
"Print DOM comment and URL to buffer." | |
(let ((comments (dom-by-class dom "^athing comtr$")) | |
(title (hnreader--get-title dom)) | |
(info (hnreader--get-post-info dom)) | |
(more-link (dom-by-class dom "morelink"))) | |
(with-current-buffer (hnreader--get-hn-comment-buffer) | |
(read-only-mode -1) | |
(erase-buffer) | |
(insert "#+STARTUP: overview indent\n") | |
(insert "#+TITLE: " (car title)) | |
(insert (format "\n%s\n[[eww:%s][view story in eww]]\n" (cdr title) (cdr title))) | |
(insert (car info)) | |
(when (cdr info) | |
(insert "\n") | |
(hnreader--print-node (cdr info))) | |
(dolist (comment comments) | |
;; (setq thanh comment) | |
(insert (format "%s %s\n" | |
(hnreader--get-indent | |
(hnreader--get-img-tag-width comment)) | |
(hnreader--get-comment-owner comment))) | |
(hnreader--print-node (hnreader--get-comment comment)) | |
(let ((reply-str (format "%s" comment))) | |
(string-match "\\(reply\\?id=.*?\\))" (format "%s" reply-str)) | |
(let ((reply-code (substring reply-str (match-beginning 1) (match-end 1)))) | |
(insert (format "\n[[https://news.ycombinator.com/%s][reply]]" reply-code)) | |
(insert (format " [[eww:https://news.ycombinator.com/%s][reply on eww]]" reply-code))))) | |
;;(insert (format "\n[[https://news.ycombinator.com/%s][reply]]" (cdaar (cdaddr (cadddr (caddar (cdddar (dom-by-class comment "^reply$")))))))) | |
;;(insert (format " [[eww:https://news.ycombinator.com/%s][reply on eww]]" (cdaar (cdaddr (cadddr (caddar (cdddar (dom-by-class comment "^reply$"))))))))) | |
(when more-link | |
(insert "\n* " (format "[[elisp:(hnreader-comment \"%s\")][More]]" (concat "https://news.ycombinator.com/" | |
(dom-attr more-link 'href))))) | |
(insert "\n* " (format "[[elisp:(hnreader-comment \"%s\")][Reload]]" url)) | |
(insert (format "\n* [[%s][Open comments in browser]]" url) ) | |
(insert (format "\n* [[eww:%s][Open comments in eww]]" url) ) | |
(org-mode) | |
;; (org-shifttab 3) | |
(goto-char (point-min)) | |
(forward-line 2)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment