Published on November 23, 2019
Last updated on December 5, 2019
Categories: computing, emacs and upgrade
Debuggery

Some fields hidden!

{'html': '

Before this morning, I had two barebones Emacs commands which I used to open my website in a browser. One opened the index page in the build folder, and one opened the index page on the deployed site.

\n
\n\n(defun mj/browse-my-website ()\n  (interactive)\n  (browse-url "https://www.maxwelljoslyn.com"))\n\n(defun mj/browse-my-website-locally ()\n  (interactive)\n  (browse-url site-build-folder))\n\n
\n

Since I frequently used the "browse-locally" command to check how the site looks before deploying, but rarely used the command to browse the deployed site, I turned the latter into an option triggered by passing an argument.

\n

More substantially, browsing the index page is still the default, but if I\'m viewing a webpage\'s source in Emacs, the command instead browses that page on the (local or deployed) site. This is usually what I want when checking pages.

\n

Here is the new and improved command.

\n
\n\n(defun mj/browse-my-website (arg)\n  "If visiting a webpage source file,\n  open corresponding page on the site.\n  Otherwise, browse the homepage. \n\n  Local browsing is the the default.\n  With prefix ARG, browse deployed site instead."\n  (interactive "P")\n  (let ((site-name\n         (if arg\n           "https://www.maxwelljoslyn.com/"\n           site-build-folder))\n        (visited-file (buffer-file-name))\n        (path))\n    (cond\n     ((not visited-file)\n      (setq path "index"))\n\n     ((string-match blog-post-regex visited-file)\n      (setq path  (concat "blog/"\n                          (match-string 1 visited-file))))\n     ((string-match article-regex visited-file)\n      (setq path (match-string 1 visited-file)))\n\n     (t\n      (setq path  "index")))\n    (browse-url (concat site-name path))))\n\n
\n'}

Maxwell Joslyn's Test Website

GitHub, Email