From fcf126f8aab283078111f8dac0b589e51f30f0ce Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 20 Jul 2023 21:26:38 +1000 Subject: Adding functions to get html url --- wiki-engine.el | 20 +++++++++++++++++--- wiki-markup.el | 10 +++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/wiki-engine.el b/wiki-engine.el index 6da4ad2..74dbe15 100644 --- a/wiki-engine.el +++ b/wiki-engine.el @@ -29,6 +29,17 @@ (require 'wiki-utils) (require 'wiki-markup) +(defun wiki-engine-html-url (site title) + "Return the url of the html webpage of TITLE on SITE." + (format "%s%s" (plist-get (alist-get site wiki-sites) :base-url) + title)) + +(defun wiki-current-html-url () + "Return the url of the html webpage of the current wiki buffer." + (unless (and wiki-site wiki-title) + (error "Nil wiki-site or wiki-title!")) + (wiki-engine-html-url wiki-site wiki-title)) + (defun wiki-engine-mediawiki-fetch (wiki-site title) "Fetch a mediawiki entry describing TITLE. @@ -47,7 +58,8 @@ The site handle is passed as a symbol WIKI-SITE." (wiki-locate-dir wiki-site) (lambda () (wiki-mode) - (setq-local wiki-site wiki-site) + (setq-local wiki-site wiki-site + wiki-title title) ) )))) @@ -65,7 +77,8 @@ The site handle is passed as a symbol WIKI-SITE." (wiki-locate-dir wiki-site) (lambda () (wiki-mode) - (setq-local wiki-site wiki-site) + (setq-local wiki-site wiki-site + wiki-title title) ) title)))) @@ -83,7 +96,8 @@ The site handle is passed as a symbol WIKI-SITE." (wiki-locate-dir wiki-site) (lambda () (wiki-mode) - (setq-local wiki-site wiki-site) + (setq-local wiki-site wiki-site + wiki-title title) ) title)))) diff --git a/wiki-markup.el b/wiki-markup.el index f29ac52..f0f26cb 100644 --- a/wiki-markup.el +++ b/wiki-markup.el @@ -74,7 +74,9 @@ (defvar wiki-outline-re "=+.*=+\ *$") (defvar-local wiki-site nil - "The identifier of the wiki site") + "The identifier of the site of the current wiki buffer.") +(defvar-local wiki-title nil + "The title of the current wiki buffer.") (defun wiki-follow-wikilink-action (data) "Button action to follow a wikilink" (funcall (wiki-site-fetcher wiki-site) (alist-get 'target data))) @@ -93,6 +95,11 @@ This can be overriden with .dir-locals.el." 'local)))) ) +(defun wiki-guess-title () + "Guess `wiki-title' from the file name." + (unless wiki-title + (setq-local wiki-title (file-name-base (buffer-file-name))))) + (defun wiki-outline-level () (when (looking-at "\\(=+\\).*[^=]\\(=+\\)\\ *$") (min (length (match-string 1)) @@ -261,6 +268,7 @@ This can be overriden with .dir-locals.el." (setq-local wiki-site (intern wiki-site))) (add-hook 'wiki-mode-hook 'wiki-guess-site) +(add-hook 'wiki-mode-hook 'wiki-guess-title) (provide 'wiki-markup) ;;; wiki-markup.el ends here -- cgit v1.2.3