Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

jagne kvrj, ngochan1126@hotmail.­com, a asdfghjhhjjkl', cvezrtg, chink chinese frankies, lambhead@rocketmail.com, priwalfdept77@yahoo.de, from scipy.optimize import minpack2 ImportError: DLL load failed: 找不到指定的模块。, yamlå, adfghjshjklç

Links

XODOX
Impressum

#1: [心得]用lisp生成网页导航、索引

Posted on 2012-09-07 09:57:15 by 觉知的机器

[b]1 ç¼èµ·[/b]

ç¨org-modeææ¥å­äºï¼åäºäºç¬è®°ï¼é¶æçæäºç½é¡µï¼æè¿å­¦ä¹ elispï¼ç¨å­¦å°çç¥è¯ï¼å äºç½é¡µçèªå¨çæç´¢å¼ï¼ä¸ºä»£ç æ¾ç¤ºå ä¸æ¼äº®çå¾çæ¡ï¼èªå·±æºæ»¡æï¼æ»ç»ä¸ä¸:)ï¼è¯·çççindexçé¢ã

é¦åï¼å¨~/org/journal/中åç¬è®°ï¼è¾åºç®å½ä¸º~/org_htmlï¼å¨.emacs中å ä¸ï¼

1: (setq org-publish-project-alist
2: '(("myorg"
3: :base-directory "~/org/journal/"
4: :publishing-directory "~/org_html/"
5: :section-numbers nil
6: :table-of-contents nil
7: :style "<link rel=\"stylesheet\"
8: href=\"css/core.css\"
9: type=\"text/css\">")))

[b]2 æ·»å å¯¼èª

2.1 è¦æ±[/b]

ç¨org-exportçæçhtml中没æ导èªï¼è¦ç»ï¿½æ¡é«å�添å å¯¼èªæ¯ä¸ä»¶æ èçäºï¼ææ³ è®©emacsèªå¨æ«æç®å½ï¼æ¾å°htmlæ件ï¼èªå¨å ä¸å¯¼èª

[b]2.2 å®ç°æ¹æ³[/b]

ç¨org-exportçæçhtmlæ件é½æå¦ä¸é¨åï¼

.. çç¥ ...
<div id="preamble">

</div>

<!-- æç®æ·»å å¯¼èªçå°æ¹ -->

<div id="content">
<h1 class="title">machine index</h1>
.. çç¥ ...

å¨æå®ä½ç½®æ·»å å¦ä¸ä¸æ®µï¼

<div class="nav">
<ul> Menu
<li><a href="#">top</a></li>
<li><a href="index.html">index</a></li>
</ul>
</div>

计åè¿æ ·å®ç°è¦æ±ï¼

* æå¼æ件
* å¦æ没ææ¾å°<div class="nav">â¦</div>ï¼å°±éè¦æ·»å å¯¼èª
* æ¾å°<div id="content">
* ç¨html-modeçsgml-skip-tag-backwardå½æ°å°åæ ç§»å°|<div id="content">
* æå¥å¯¼èªç代ç æ®µ

[b]2.3 æ·»å å¯¼èª[/b]

1: (setq changedItems '())
2:
3: (defun machine_make_html_tranlate (file)
4: "tranlate htmlæ件.
5: 1. å¢å å¯¼èª
6: 2. ç»ä»£ç æ·»å å¾çæ¡"
7: (let (name buffer text star end)
8: (find-file file)
9: (setq name (file-name-nondirectory file))
10: (setq buffer (get-file-buffer name))
11: (goto-char (point-min))

注ææåä¸å¥ï¼(setq changedItems (cons â¦ï¼ç¨äºè®°å½æ·»å å¯¼èªæ ä½ï¼changedItemsçå®ä¹å¨ç¬¬ä¸è¡ã

å¾ç»­...






--

[upload=1][/upload]
â» ä¿®æ¹:ã»awareness äº Sep 7 17:57:14 2012 ä¿®æ¹æ¬æã»
â» æ¥æº:ã»æ°´æ¨ç¤¾åº http://newsmth.netã»[FROM: 118.181.195.*]

Report this message

#2: Re: [心得]用lisp生成网页导航、索引

Posted on 2012-09-07 13:51:33 by 觉知的机器

[b]3 ç»ä»£ç æ·»å¾çæ¡

3.1 è¦æ±[/b]

æ¾ç»å¨ å¼ é©°å çç½é¡µçå°codeå¨å´ï¼æåemacsç¯å¢å¾çï¼è§http://lifegoo.pluskid.org/wiki/EmacsSmartCompile.htmlï¼å¾å欢ï¼ä¹æ³å¼ä¸ä¸ã

å æ­¤å®ç°æ¹å¼ç±ä»¥ä¸æ­¥éª¤ç»æï¼

* å解codeçåºå¾ï¼åæ6个ç¬ç«çå°å¾ç
* å®ä¹6个å¾ççcss
* å¨htmlæ件中æ¾å°"<pre class="src"ï¼å¨è¿å¥ä¹åæ·»å ï¼


<div class=\"emacs-outer\">
<div class=\"emacs-title-right\">
<div class=\"emacs-title-left\">
<div class=\"emacs-cont-left\">
<div class=\"emacs-cont-right\">
<div class=\"emacs-footer-right\">
<div class=\"emacs-footer-left\">


æ¾å°</pre>ï¼å¨è¿å¥ä¹åæ·»å :

</div></div></div></div></div></div>

å¨css中ï¼å®ä¹åºå¾çå®ä¹ï¼

.emacs-title-left {
background-image: url(../images/title-left.png);
background-position: top left;
background-repeat: no-repeat;
padding: 0;
padding-top: 30px;
}

.emacs-title-right {
background-image: url(../images/title-right.png);
background-position: top right;
background-repeat: no-repeat;
padding: 0;
}

.emacs-cont-left {
background-image: url(../images/cont-left.png);
background-position: top left;
background-repeat: no-repeat;
padding: 0;
}

.emacs-cont-right {
background-image: url(../images/cont-right.png);
background-position: top right;
background-repeat: no-repeat;
padding: 0;
}

.emacs-footer-right {
background-image: url(../images/footer-right.png);
background-position: bottom right;
background-repeat: no-repeat;
padding: 0;
}

.emacs-footer-left {
background-image: url(../images/footer-left.png);
background-position: bottom left;
background-repeat: no-repeat;
padding: 0;
padding-bottom: 16px;
padding-left: 15px;
padding-right: 3px;
}

[b]3.3 æ·»å å¾çæ¡[/b]

1: ... çç¥ ...
2: ;; for code add round image
3: (goto-char (point-min))
4: (while (search-forward "<pre class=\"src" nil t)
5: (sgml-skip-tag-backward 1)
6: (beginning-of-line)
7: (backward-char 1)
8: (beginning-of-line)
9: (setq text (buffer-substring-no-properties (1+ (point)) (+ (point) 4)))
10: (if (not (string= "div" text))
11: (progn
12: (insert (concat "<div class=\"emacs-outer\">\n"
13: "<div class=\"emacs-title-right\">\n"
14: "<div class=\"emacs-title-left\">\n"
15: "<div class=\"emacs-cont-left\">\n"
16: "<div class=\"emacs-cont-right\">\n"
17: "<div class=\"emacs-footer-right\">\n"
18: "<div class=\"emacs-footer-left\">"))
19: (search-forward "</pre>" nil t)
20: (insert (concat "\n" "</div>" "</div>" "</div>" "</div>" "</div>" "</div>" "</div>" "\n"))
21: (setq changedItems
22: (cons (concat "tranlate " (buffer-file-name) "'s code at " (number-to-string (line-number-at-pos)))
23: changedItems)))
24: (search-forward "</pre>" nil t)))
25: ... çç¥ ...

* (sgml-skip-tag-backward 1)ï¼sgml-mode中ï¼è·³å°tagçå¼å§
* (beginning-of-line)ï¼åæ ç§»å°è¡é¦
* (if (not (string= "div" text))ï¼å¤æ­æ¯å¦å·±ç»æå¾çæ¡
* (setq changedItems (cons (concat â¦ï¼æ·»å ï¿½cæ¹è®°å½

å¾ç»­...
--

â» æ¥æº:ã»æ°´æ¨ç¤¾åº http://newsmth.netã»

Report this message

#3: Re: [心得]用lisp生成网页导航、索引

Posted on 2012-09-07 13:55:14 by 觉知的机器

[b]4 æ ¹æ®å¾ç大å°ï¼ï¿½cæ¹å¾çhtml[/b]

[b]4.1 è¦æ±[/b]

org-exportçæçimgæ¯è¿æ ·çï¼

<a href="#"><img src="images/emacs-image1.jpg" alt="emacs-image1.jpg"/></a>


没æå®ä¹å¾çç��度ï¼æéè¦æ ¹æ®å¾ç大å°æ·»å widthï¼åæ¶å»é¤å¾çå¤ç<a href="#">ã

* å¦å¾ç��度æ¯430ï¼é£ä¹ï¿½cæ¹æçimg

<img src="images/emacs-image1.jpg" alt="images/emacs-image1.jpg" width="430"/>


å¦å¾ç太��ï¼å¤§äº800ï¼å¦å¾ç��度1600ï¼é£ä¹ï¿½cæ¹æçimg

<img src="images/emacs-image1.jpg" alt="images/emacs-image1.jpg" width="800"/>


[b]4.2 å®ç°æ¹æ³[/b]

* æ¾å°html代ç ä¸­çimgï¼ååºå¾çæ件å
* ç¨identify -format "%w" filenameï¼å¾å°å¾ç��度
* ��度大å­800ï¼ç¨replace-matchï¼ï¿½cæ¹widthï¼"800"
* ��度å°äº800ï¼ç¨replace-matchï¼ï¿½cæ¹widthï¼"å®é��度"

[b]4.3 �cæ¹å¾çhtml[/b]

1: ;; image width
2: (goto-char (point-min))
3: (while (re-search-forward "<a href=\"[^\"]+\"><img src=\"\\([^\"]+\\)\" alt=\"[^\"]+\"/></a>" nil t)
4: (setq name (match-string-no-properties 1))
5: (setq string
6: (shell-command-to-string
7: (concat "identify -format \"%w\" " org_html_path name)))
8: (setq width (string-to-number string))
9: (if (> width 800)
10: (replace-match "<img src=\"\\1\" alt=\"\\1\" width=\"800\"/>")
11: (replace-match "<img src=\"\\1\" alt=\"\\1\" width=\"" width "\"/>"))
12: (setq changedItems
13: (cons (concat "tranlate " (buffer-file-name) "'s image at " (number-to-string (line-number-at-pos)))
14: changedItems)))

* shell-command-to-stringï¼å¨elisp中è°ç¨shellå½ä»¤
* (setq changedItems (cons (concat â¦ï¼æ·»å ï¿½cæ¹è®°å½

å¾ç»­...

--

â» æ¥æº:ã»æ°´æ¨ç¤¾åº http://newsmth.netã»

Report this message

#4: Re: [心得]用lisp生成网页导航、索引

Posted on 2012-09-07 13:57:10 by 觉知的机器

[b]5 综å[/b]

ç°å¨ï¼æè½å¯¹ä¸ä¸ªhtmlæ件ï¼

1. å¢å å¯¼èª
2. ç»ä»£ç æ·»å å¾çæ¡
3. æ ¹æ®å¾ç大å°ï¼ï¿½cæ¹å¾çhtml

org-exportçæçè¥äºhtmlæ件ï¼é½éè¦åå¤çï¼ææ³ç¨ä¸ä¸ªå½æ°å®ç°ï¼è¿å°ç®çï¼

* èªå¨å¨org-exportç®æ ç®å½ä¸­æ¾å°ææhtmlæ件ï¼æ¾å¥list
* ç¨mapcarå¤ç�æ¡é«å�
* è®°å½ï¿½èæ¡é¾ï¿½çï¼å¨é¨æ件å¤çå®æåï¼æ¾ç¤ºå°ä¸´æ¶buffer中

[b]5.1 å个æ件转æ¢å½æ°[/b]

å®æï¼

1. å¢å å¯¼èª
2. ç»ä»£ç æ·»å å¾çæ¡
3. æ ¹æ®å¾ç大å°ï¼ï¿½cæ¹å¾çhtml

1: ;; org public path
2: (setq org_html_path "~/org_html/")
3: (setq changedItems '())
4:
5: (defun machine_make_html_tranlate (file)
6: "tranlate htmlæ件.
7: 1. å¢å å¯¼èª
8: 2. ç»ä»£ç æ·»å å¾çæ¡
9: 3. æ ¹æ®å¾ç大å°ï¼ï¿½cæ¹å¾çhtml"
10: (let (name buffer text star end)
11: (find-file file)
12: (setq name (file-name-nondirectory file))
13: (setq buffer (get-file-buffer name))
14: (goto-char (point-min))
15: ;; nav
16: (if (not (search-forward "<div class=\"nav\"" nil t))
17: (progn
18: (search-forward "<div id=\"content\"" nil t)
19: (sgml-skip-tag-backward 1)
20: (insert (concat "<div class=\"nav\">\n"
21: " <ul> Menu\n"
22: " <li><a href=\"#\">top</a></li>\n"
23: " <li><a href=\"index.html\">index</a></li>\n"
24: " </ul>\n"
25: "</div>\n\n"))
26: (setq changedItems (cons (concat "add " (buffer-file-name) "'s nav.") changedItems))))
27: ;; for code add round image
28: (goto-char (point-min))
29: (while (search-forward "<pre class=\"src" nil t)
30: (sgml-skip-tag-backward 1)
31: (beginning-of-line)
32: (backward-char 1)
33: (beginning-of-line)
34: (setq text (buffer-substring-no-properties (1+ (point)) (+ (point) 4)))
35: (if (not (string= "div" text))
36: (progn
37: (insert (concat "<div class=\"emacs-outer\">\n"
38: "<div class=\"emacs-title-right\">\n"
39: "<div class=\"emacs-title-left\">\n"
40: "<div class=\"emacs-cont-left\">\n"
41: "<div class=\"emacs-cont-right\">\n"
42: "<div class=\"emacs-footer-right\">\n"
43: "<div class=\"emacs-footer-left\">"))
44: (search-forward "</pre>" nil t)
45: (insert (concat "\n" "</div>" "</div>" "</div>" "</div>" "</div>" "</div>" "</div>" "\n"))
46: (setq changedItems
47: (cons (concat "tranlate " (buffer-file-name) "'s code at " (number-to-string (line-number-at-pos)))
48: changedItems)))
49: (search-forward "</pre>" nil t)))
50: ;; image width
51: (goto-char (point-min))
52: (while (re-search-forward "<a href=\"[^\"]+\"><img src=\"\\([^\"]+\\)\" alt=\"[^\"]+\"/></a>" nil t)
53: (setq name (match-string-no-properties 1))
54: (setq string
55: (shell-command-to-string
56: (concat "identify -format \"%w\" " org_html_path name)))
57: (setq width (string-to-number string))
58: (if (> width 800)
59: (replace-match "<img src=\"\\1\" alt=\"\\1\" width=\"800\"/>")
60: (replace-match "<img src=\"\\1\" alt=\"\\1\" width=\"" width "\"/>"))
61: (setq changedItems
62: (cons (concat "tranlate " (buffer-file-name) "'s image at " (number-to-string (line-number-at-pos)))
63: changedItems)))
64: (if (not (buffer-modified-p))
65: (kill-this-buffer)
66: (progn
67: (save-buffer)))))

* (if (not (buffer-modified-p))ï¼å¤æ­bufferæ¯å¦å·±ï¿½cæ¹
* æªï¿½cæ¹ï¼kill-this-buffer
* 己�cæ¹ï¼save-bufferï¼å¹¶ä¿ææå¼

[b]5.2 å¤ç�æ¡é«å�[/b]

1: (defun org-html-tranlate ()
2: "转�Qorg public pathä¸çææhtml.
3: å¨æ件中è¾åºlog."
4: (interactive)
5: (setq changedItems '())
6: (setq outputBuffer "*machine org html tranlate output*")
7: (with-output-to-temp-buffer outputBuffer
8: (mapcar 'machine_make_html_tranlate
9: (find-lisp-find-files org_html_path "\\.html$"))
10: (mapcar 'print (reverse changedItems))
11: (princ "\n\n--- Done deal! ---")))

* ç¨(find-lisp-find-files org_html_path "\\.html$"))ï¼å¨org_html_pathç®å½ä¸å¯» æ¾htmlæ件
* (mapcar 'machine_make_html_tranlate â¦ï¼å¯¹ï¿½æ¡é«å�è°ç¨ machine_make_html_tranlate
* (with-output-to-temp-buffer outputBuffer â¦ï¼å¨outputBuffer中æ¾ç¤ºï¿½cæ¹è®°å½
* (reverse changedItems)ï¼å° changedItemsååº

å¾ç»­...
--

â» æ¥æº:ã»æ°´æ¨ç¤¾åº http://newsmth.netã»

Report this message

#5: Re: [心得]用lisp生成网页导航、索引

Posted on 2012-09-07 14:01:01 by 觉知的机器

[b]6 çæindex.html[/b]

[b]6.1 è¦æ±[/b]

ææå¾å¤ç¬è®°ï¼åæemacsãlinuxãlatexãworkç­ç±»ï¼ï¿½é¸é»¾å³æ¡è§¯ï¿½å¨ç´¢å¼æ件 (index.html)中é½è¦ï¿½cæ¹ï¼å¾ç¦ï¼ææ³è®©èªå¨æ¶éç®å½ä¸çæ件ï¼å¹¶åç±»ï¼çæ index.htmlï¼å¤æ¹ä¾¿ã

[b]6.2 å®ç°æ¹æ³[/b]

å建ç«index.htmlæ¡æ¶ï¼å°éè¦çç±»å«å好ï¼

... çç¥ ...
<div id="table-of-contents">
<h3>emacs</h3>
</div>

<div id="table-of-contents">
<h3>latex</h3>
</div>

<div id="table-of-contents">
<h3>linux</h3>
</div>

<div id="table-of-contents">
<h3>c/c++</h3>
</div>

<div id="table-of-contents">
<h3>java</h3>
</div>

<div id="table-of-contents">
<h3>work</h3>
</div>

<div id="table-of-contents">
<h3>other</h3>
</div>
... çç¥ ...


* å¨dired-mode中ï¼é中è¥äºæ件
* ç»å®ç±»å«åï¼å¨index.html中ï¼æ¾å°ç±»å«æå¨ä½ç½®
* ä¾æ¬¡æå¼æ件ï¼æ¾å°æ件titleï¼ç¨titleä½ä¸ºæ件çé¾æ¥å
* æ´æ°index.htmlçæ¥æ


[b]6.3 çæindex[/b]

1: (defun org-make-html-index (type)
2: "get the ç¹å®ç±»åç html,å¨ index.html 中åç±»."
3: (interactive "stype: ")
4: (let (text name title filename list start)
5: (setq list (dired-get-marked-files))
6: (setq name "index.html")
7: (setq filename (concat org_html_path name))
8: (if (not (file-exists-p filename))
9: (error "no %s" name))
10: (find-file filename)
11: (goto-char (point-min))
12: (setq text nil)
13: (while (not (string= text type))
14: (if (not (search-forward "<h3>" nil t))
15: (error "no %s type" type))
16: (setq start (point))
17: (search-forward "</h3>")
18: (backward-char 5)
19: (setq text (buffer-substring-no-properties start (point))))
20: ;; find type
21: (search-forward "</div>" nil t)
22: (forward-char 1)
23: (setq start (point))
24: (search-forward "<div id=\"table-of-contents\"" nil t)
25: (beginning-of-line)
26: (delete-region start (point))
27: (mapcar
28: (lambda (name)
29: (find-file name)
30: (goto-char (point-min))
31: (search-forward "<title>" nil t)
32: (setq start (point))
33: (search-forward "</title>" nil t)
34: (backward-char 8)
35: (setq title (buffer-substring-no-properties start (point)))
36: (bury-buffer)
37: (insert (concat "\n" "<div id=\"outline-container\">"
38: "<a href=\"" (file-name-nondirectory name) "\">"
39: title "</a>\n" "</div>" "\n")))
40: list)
41: (insert "\n")
42: ;; update date
43: (search-forward "<p class=\"date\">Date: " nil t)
44: (setq start (point))
45: (search-forward "</p>" nil t)
46: (backward-char 4)
47: (delete-region start (point))
48: (insert (format-time-string "%Y-%m-%d %H:%M:%S"))
49: (save-buffer)))


* è¿å½æ°è¦å¨dired-mode中è¿è¡
* (interactive "stype: ")ï¼æ示è¾å¥ç±»åï¼"s"表示è¾å¥å­ç¬¦ä¸²ï¼å¶ä»è¾å¥æ¹å¼å è§ï¼(info)interactive
* (setq list (dired-get-marked-files))ï¼ååºmarked files
* å¦éå¨index.html中æ¾ä¸å°typeï¼éåº

.. çç¥ ...
(while (not (string= text type))
(if (not (search-forward "<h3>" nil t))
(error "no %s type" type))
.. çç¥ ...

* (delete-region start (point))ï¼å é¤type��æçæ件é¾æ¥
* (setq title (buffer-substring-no-properties start (point)))ï¼å¯»æ¾æ件ç title
* (insert (format-time-string "%Y-%m-%d %H:%M:%S"))ï¼æ´æ°æ¥æ

emacs is pretty.
--

â» æ¥æº:ã»æ°´æ¨ç¤¾åº http://newsmth.netã»

Report this message