diff options
author | Thanh Vuong <thanhvg@gmail.com> | 2019-08-24 10:33:20 -0600 |
---|---|---|
committer | Thanh Vuong <thanhvg@gmail.com> | 2019-08-24 10:33:20 -0600 |
commit | fcc90d466ebf43202485d3ba1f0a8f314df7f5ae (patch) | |
tree | 029432813be2d0f3b50c0e9c44e5bf1683460c6c | |
parent | 8d43e8ff4b2898da80777add561719149e0bbee4 (diff) |
add info in comment page
-rw-r--r-- | TODOs.org | 2 | ||||
-rw-r--r-- | hnreader.el | 26 |
2 files changed, 18 insertions, 10 deletions
@@ -86,6 +86,6 @@ Assuming the current buffer is an org-mode buffer, the following code collects p In an org buffer, (org-element-parse-buffer) returns the parse tree of the current buffer. And you can map over it with org-element-map. * DONE first run on comment buffer won't have right width also need to shadow shr-use-fonts to nil -* TODO display OP post ins ask and OP infor +* DONE display OP post ins ask and OP infor class fatitem is 4 long when ask it's 5 items long just take from 1 to the peniculate item with seq-take and seq-drop diff --git a/hnreader.el b/hnreader.el index 9b03736..1a0865e 100644 --- a/hnreader.el +++ b/hnreader.el @@ -103,11 +103,17 @@ third one is 80.") (defun hnreader--get-post-info (dom) "Get top info about the DOM comment page." (let* ((fat-item (dom-by-class dom "^fatitem$")) - (tr-tag (dom-by-tag fat-item 'tr))) - (setq thanh fat-item) - (setq thanh-dom dom) - (seq-drop (seq-take tr-tag (- (length tr-tag) 1)) 1))) - + (user (dom-by-class fat-item "^hnuser$")) + (score (dom-by-class fat-item "^score$")) + (tr-tag (dom-by-tag fat-item 'tr)) + (intro (if (= (length tr-tag) 6) + (nth 3 tr-tag) + nil))) + (cons + (format "%s | by %s\n" + (dom-text score) + (dom-text user)) + intro))) (defun hnreader--print-node (node) "Print the NODE with extra options." @@ -118,16 +124,18 @@ third one is 80.") (defun hnreader--print-comments (dom) "Print DOM comment page to buffer." (let ((comments (dom-by-class dom "^athing comtr $")) - (title (hnreader--get-title dom))) + (title (hnreader--get-title dom)) + (info (hnreader--get-post-info dom))) (with-current-buffer (hnreader--get-hn-comment-buffer) (read-only-mode -1) (erase-buffer) (insert "#+STARTUP: indent\n") (insert "#+TITLE: " (car title)) (insert (format "\n%s\n[[eww:%s][view story in eww]]\n" (cdr title) (cdr title))) - (mapc #'hnreader--print-node (hnreader--get-post-info dom)) - ;; (hnreader--print-node (hnreader--get-post-info dom)) - ;; (insert "\n" (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" |