Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browsing reddit page from URL #37

Open
Andre0991 opened this issue Aug 3, 2022 · 4 comments
Open

Browsing reddit page from URL #37

Andre0991 opened this issue Aug 3, 2022 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Andre0991
Copy link

Hi. Given a reddit URL that points to a discussion (such as 1), would it be possible to browse that with md4rd?
I haven't found any command for this, but I might be missing something.

Use case: I sometimes find reddit threads in Google results in eww. Their rendering is a bit confusing, though. So I'd like to use a specialized packaged for browsing threads.

@ahungry
Copy link
Owner

ahungry commented Aug 4, 2022

I don't think it'd be a hard thing to add better facilities around - for example, just appending a .json to the end of your link/url will enable the querying of the page itself as an API response (https://old.reddit.com/r/emacs/comments/wf0t0d/weekly_tips_tricks_c_thread.json), which we can easily plug into the existing render method, as such:

(md4rd--fetch-comments "https://old.reddit.com/r/emacs/comments/wf0t0d/weekly_tips_tricks_c_thread.json")

This will produce the md4rd buffer of just that conversation.

A neat addition might be a small function that takes a reddit URL and appends the .json + calls that function (maybe eww has some type of hook where you could bypass the eww rendering/page open event, and instead run this new idea)

@ahungry ahungry added enhancement New feature or request help wanted Extra attention is needed labels Aug 4, 2022
@treed
Copy link

treed commented Apr 25, 2023

I believe I have something like this working:

  (defun md4rd-open-post (url &rest _args)
    (md4rd--fetch-comments (concat (string-replace "www" "old" url) ".json")))

  (push (cons
	 (rx line-start "http" (zero-or-one "s") ":https://www.reddit.com/" (one-or-more anychar))
	 #'md4rd-open-post)
	browse-url-handlers))

This is sufficient to cause reddit posts to open in md4rd when I hit b in elfeed-entry.

Note that browse-url-handlers is new to emacs 28; something like this is possible in prior versions, but I don't currently have an example at hand. I can dig it out of my git history if needed.

@Andre0991
Copy link
Author

Andre0991 commented Nov 21, 2023

Hi folks.

Great, @treed, thanks for that code snippet.
In my setup, using browse-url-handlers as you did was not enough for making eww open md4rd when opening a reddit link (from a Google search, for example).

However, adding a hook to eww-after-render-hook did the trick.
Example:

(use-package eww
  :preface
  (defvar apt-reddit-url-regex
    (rx line-start "http" (zero-or-one "s") ":https://www.reddit.com/" (one-or-more anychar)))
  (defun apt-open-reddit-if-url-matches ()
    (when (string-match-p apt-reddit-url-regex (or (eww-current-url) ""))
      (md4rd-open-post (eww-current-url))))
  :hook ((eww-after-render-hook . apt-open-reddit-if-url-matches)))

@ahungry
Copy link
Owner

ahungry commented Nov 22, 2023

Awesome, ty for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants