;-*- coding: utf-8 -*- ; part of Xah Lee's emacs init file. ; 2011-05-27 ; Xah Lee, ; ∑ http://xahlee.org/ (defun xahsite-p (xah-url) "Returns t if XAH-URL is a xah website, else nil. Xah sites are: xahlee.org xahlee.info xahporn.org ergoemacs.org" (interactive) (if (string-match "^http://xahlee\\.org\\|^http://xahlee\\.info\\|^http://xahporn\\.org\\|^http://ergoemacs\\.org" (replace-regexp-in-string "^http://www\\." "http://" xah-url) ) t nil )) (defun xahsite-url-to-filepath (xah-url) "Returns the file path on disk of a xah website URL XAH-URL. e.g. 〔http://xahlee.org/index.html〕 ⇒ 〔~/web/xahlee_org/index.html〕. If input XAHURL is not a xah site, return as is. This function does not check input nor if the result path file exists. e.g. 〔http://some.org/〕 ⇒ 〔http://some.org/index.html〕 〔some water〕 ⇒ 〔some water〕" (interactive) (let ( (webRootPath "~/web/") ;; (webRootPath "/media/HP/Users/xah/web/") ( ξurl xah-url)) ;; remove html named anchor in path, e.g. http://xahlee.org/emacs/elisp.html#comment-113416750 (setq ξurl (replace-regexp-in-string "#.+$" "" ξurl)) ;; remove www (setq ξurl (replace-regexp-in-string "^http://www\\." "http://" ξurl)) ;; add file name if none (setq ξurl (replace-regexp-in-string "/$" "/index.html" ξurl)) (cond ((string-match "^http://xahlee\\.org/" ξurl ) (replace-regexp-in-string "^http://xahlee.org/" (concat webRootPath "xahlee_org/") ξurl)) ((string-match "^http://xahlee\\.info/" ξurl ) (replace-regexp-in-string "^http://xahlee.info/" (concat webRootPath "xahlee_info/") ξurl)) ((string-match "^http://xahporn\\.org/" ξurl ) (replace-regexp-in-string "^http://xahporn.org/" (concat webRootPath "xahporn_org/") ξurl)) ((string-match "^http://ergoemacs\\.org/" ξurl ) (replace-regexp-in-string "^http://ergoemacs.org/" (concat webRootPath "ergoemacs_org/") ξurl)) (t ξurl ) ; return as is ) ) ) (defun xahsite-filepath-to-url (webpath) "Turn my website path WEBPATH to my site's URL. For example, the following path: C:/Users/xah/web/xahlee_org/emacs/emacs.html or /Users/xah/web/xahlee_org/emacs/emacs.html will become: http://xahlee.org/emacs/emacs.html" (let ((ff webpath)) ;; (setq ff (replace-regexp-in-string "^C:" "" ff)) ;; (setq ff (replace-regexp-in-string "^/Users/xah/web/xahlee_org/" "http://xahlee.org/" ff)) (setq ff (expand-file-name ff)) (setq ff (replace-regexp-in-string "^c:" "" ff)) (setq ff (replace-regexp-in-string "^C:" "" ff)) (setq ff (replace-regexp-in-string "^/Users/xah/web/" "" ff)) (setq ff (replace-regexp-in-string "^/Users/h3/web/" "" ff)) (setq ff (replace-regexp-in-string "^/home/ubuntu/web/" "" ff)) (setq ff (replace-regexp-in-string "^xahlee_org" "http://xahlee.org" ff)) (setq ff (replace-regexp-in-string "^ergoemacs_org" "http://ergoemacs.org" ff)) (setq ff (replace-regexp-in-string "^xahlee_info" "http://xahlee.info" ff)) (setq ff (replace-regexp-in-string "^xahporn_org" "http://xahporn.org" ff)) ff ) )