;; -*- coding: utf-8 -*- ;; part of Xah Lee's emacs init file. ;; 2011-05-28 ;; Xah Lee, ;; ∑ http://xahlee.org/ (defun make-blogger-entry () "Make a blogger entry. Copy the current buffer. create a new buffer. Make it html-mode. paste it in. remove the header and footer. fix all relative links to http://xahlee.org/ links. add a “Perm URL with updates: ‹link›” sentence at top. This new content is ready to be posted to blogger." (interactive) (let (bds p1 p2 cssStr mainText thisFilePath currentDir newBuff permLink) (setq bds (get-selection-or-unit 'buffer)) (setq mainText (elt bds 0) ) (setq p1 (elt bds 1) ) (setq p2 (elt bds 2) ) (setq thisFilePath (buffer-file-name)) (setq currentDir (file-name-directory thisFilePath)) (setq newBuff (generate-new-buffer "*blogger temp*")) (switch-to-buffer newBuff) (html-mode) (insert mainText) ;; get css declaration, if any (let (p3 p4 ) (goto-char 1) (if (search-forward "") (setq p4 (point) ) (setq cssStr (buffer-substring-no-properties p3 p4)) ) (progn (setq cssStr "") ) ) ) ;; remove header (goto-char 1) (when (search-forward "
" nil t) (search-forward "
") (delete-region (point) (point-min) ) ) ;; remove fixed strings. ads, banners, donation box. (replace-pairs-region 1 (point-max) '( ["" ""] ["
blog comments powered by Disqus" ""] [" " ""] ["?tag=xahh-20" "?tag=xahblg-20"] )) (replace-regexp-pairs-region 1 (point-max) '( ["

[^<]+?

" ""] ["

[^<]+?

" ""] ["

Xah Lee, [-<>/ ,…time0-9]+?

" ""] ["
Advertise Here
" ""] ["
[ \n]+
" ""] )) ;; remove blogger link (goto-char 1) (when (search-forward "
" nil t)) (delete-region (line-beginning-position) (point-max) ) ) ;; change href links from relative to http://xahlee.org/ URL (goto-char 1) (while (search-forward "href=\"" nil t) (when (not (looking-at "http")) (let (bds myLink fPath) (setq bds (bounds-of-thing-at-point 'filename)) (setq myLink (buffer-substring-no-properties (car bds) (cdr bds))) (setq fPath (expand-file-name (concat currentDir myLink)) ) (delete-region (car bds) (cdr bds)) (insert (xahsite-filepath-to-url fPath)) ) )) ;; change inline image links from relative to http://xahlee.org/ URL (goto-char 1) (while (search-forward "src=\"" nil t) (when (not (looking-at "http")) (let (bds myLink fPath) (setq bds (bounds-of-thing-at-point 'filename)) (setq myLink (buffer-substring-no-properties (car bds) (cdr bds))) (setq fPath (expand-file-name (concat currentDir myLink)) ) (delete-region (car bds) (cdr bds)) (insert (xahsite-filepath-to-url fPath)) ) ) ) ;; (compute-url-from-relative-link thisFilePath) ;; insert perm link at top (when (and (not (string-match "blog\.html$" thisFilePath)) (not (string-match "Vocabulary_dir" thisFilePath)) ) (goto-char 1) (setq permLink (xahsite-filepath-to-url thisFilePath)) (insert "

Perm URL with updates: " "" permLink "" "

\n\n") ) ;; insert css string (goto-char 1) (insert cssStr "\n\n") (replace-regexp-pairs-region 1 (point-max) '( ["\n\n+" "\n\n"] )) (goto-char 1) (kill-new (buffer-string)) ))