Skip to content

Instantly share code, notes, and snippets.

@goncha
Created August 24, 2013 11:33
Show Gist options
  • Save goncha/6327619 to your computer and use it in GitHub Desktop.
Save goncha/6327619 to your computer and use it in GitHub Desktop.
Emacs Lisp script to merge articles from www.paulgraham.com into one single html.
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
(setq temp-articles '(
"progbot.html"
"lwba.html"
"avg.html"
"javacover.html"
"popular.html"
"langdes.html"
"rootsoflisp.html"
"road.html"
"diff.html"
"noop.html"
"taste.html"
"fix.html"
"power.html"
"icad.html"
"spam.html"
"desres.html"
"better.html"
"nerds.html"
"hundred.html"
"iflisp.html"
"hp.html"
"ffb.html"
"say.html"
"gba.html"
"wealth.html"
"gap.html"
"gh.html"
"pypar.html"
"essay.html"
"bubble.html"
"laundry.html"
"polls.html"
"charisma.html"
"usa.html"
"hs.html"
"start.html"
"venturecapital.html"
"college.html"
"writing44.html"
"mac.html"
"bronze.html"
"submarine.html"
"hiring.html"
"opensource.html"
"ladder.html"
"inequality.html"
"sfp.html"
"ideas.html"
"vcsqueeze.html"
"startupfunding.html"
"web20.html"
"procrastination.html"
"love.html"
"whyyc.html"
"6631327.html"
"softwarepatents.html"
"randomness.html"
"startuplessons.html"
"siliconvalley.html"
"america.html"
"marginal.html"
"island.html"
"copy.html"
"investors.html"
"mit.html"
"startupmistakes.html"
"goodart.html"
"foundersatwork.html"
"wisdom.html"
"notnot.html"
"microsoft.html"
"judgement.html"
"guidetoinvestors.html"
"unions.html"
"equity.html"
"stuff.html"
"head.html"
"die.html"
"colleges.html"
"philosophy.html"
"webstartups.html"
"startuphubs.html"
"newthings.html"
"trolls.html"
"ycombinator.html"
"boss.html"
"disagree.html"
"heroes.html"
"googles.html"
"good.html"
"lies.html"
"distraction.html"
"cities.html"
"prcmc.html"
"fundraising.html"
"badeconomy.html"
"artistsship.html"
"highres.html"
"divergence.html"
"credentials.html"
"identity.html"
"13sentences.html"
"hackernews.html"
"maybe.html"
"convergence.html"
"angelinvesting.html"
"relres.html"
"5founders.html"
"foundervisa.html"
"twitter.html"
"revolution.html"
"makersschedule.html"
"ramenprofitable.html"
"segway.html"
"kate.html"
"determination.html"
"nthings.html"
"publishing.html"
"discover.html"
"really.html"
"apple.html"
"organic.html"
"selfindulgence.html"
"top.html"
"addiction.html"
"future.html"
"yahoo.html"
"hiresfund.html"
"seesv.html"
"superangels.html"
"founders.html"
"tablets.html"
"control.html"
"airbnb.html"
"patentpledge.html"
"hubs.html"
"vw.html"
"schlep.html"
"word.html"
"ambitious.html"
"property.html"
"speak.html"
"todo.html"
"swan.html"
"growth.html"
"hw.html"
"startupideas.html"
"invtrend.html"
"ds.html"
"convince.html"
"herd.html"))
(dolist (article temp-articles)
(clean-article (concat "D:/kindle/tmp/" article)))
(merge-articles (cons "pg.html" temp-articles)
"D:/kindle/tmp/"
"D:/kindle/paulgraham.html")
(defun merge-articles (articles article-directory merged-filename)
(with-temp-buffer
(insert "<html>"
"<head>"
"<title>Essays of Paul Graham</title>"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">"
"<meta name=\"author\" content=\"Paul Graham\">"
"</head>"
"<body>")
(dolist (article articles)
(insert-file (concat article-directory article))
(end-of-buffer))
(insert "</body>"
"</html>")
(write-file merged-filename)))
(defun clean-article (filename)
(with-temp-buffer
(insert-file filename)
(beginning-of-buffer)
(search-forward "alt=\"")
(delete-region (region-beginning) (region-end))
(insert "<div id=\"" (file-name-nondirectory filename) "\"><h1>")
(search-forward "\"")
(backward-char 1)
(delete-char 2)
(insert "</h1>")
(search-forward "</body>")
(search-backward "</font></td></tr></table>")
(let ((pos (point)))
(end-of-buffer)
(delete-region (point) pos)
(insert "</font></div>"))
(write-file filename nil)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment