aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xpyblog36
-rw-r--r--source/blog/2014-12-23-mpv-launcher.md8
-rw-r--r--source/blog/2015-02-24-the-new-onedrive-api.md2
-rw-r--r--source/blog/2015-04-26-using-python-3-with-emacs-jedi.md2
-rw-r--r--source/css/theme.css41
-rw-r--r--source/key.md3
-rw-r--r--templates/template.html22
7 files changed, 89 insertions, 25 deletions
diff --git a/pyblog b/pyblog
index 42694cba..add06650 100755
--- a/pyblog
+++ b/pyblog
@@ -54,6 +54,7 @@ ATOM = os.path.join(BUILDDIR, "atom.xml")
INDEXHTML = os.path.join(BUILDDIR, "index.html")
FEED_MAX_ENTRIES = 20
+CODE_LINE_HEIGHT = 18
####################### END OF GENERATOR CONFIGURATIONS ########################
@@ -409,6 +410,38 @@ def generate_index_and_feed():
generate_sitemap(feed)
+def _pre_tag_insert_line_numbers(soup, pre_tag):
+ """Insert line numbers to a pre tag."""
+ num_lines = len(pre_tag.text.split("\n"))
+ for line_number in range(1, num_lines + 1):
+ # line number divs will look like:
+ # <span class="line-number" data-line="1" style="top: 0px"><!----></span>
+ # <span class="line-number" data-line="2" style="top: 18px"><!----></span>
+ ln_tag = soup.new_tag("span")
+ ln_tag["class"] = "line-number"
+ ln_tag["data-line"] = line_number
+ ln_tag["style"] = "top: %dpx" % ((line_number - 1) * CODE_LINE_HEIGHT)
+ ln_tag.append(soup.new_string("", bs4.Comment))
+ pre_tag.code.append(ln_tag)
+
+
+def number_code_lines(htmlfilepath):
+ """Insert line numbers to preformatted code blocks."""
+ with open(htmlfilepath, "r+", encoding="utf-8") as htmlfileobj:
+ soup = bs4.BeautifulSoup(htmlfileobj.read())
+ for pre_tag in soup.find_all("pre"):
+ if ((pre_tag.code is None or "class" not in pre_tag.attrs or
+ not "sourceCode" in pre_tag["class"])):
+ # not really a block of source code
+ continue
+ _pre_tag_insert_line_numbers(soup, pre_tag)
+
+ # write back
+ htmlfileobj.seek(0)
+ htmlfileobj.write(str(soup))
+ htmlfileobj.truncate()
+
+
def generate_blog(fresh=False, report_total_errors=True):
"""Generate the blog in BUILDDIR.
@@ -503,8 +536,11 @@ def generate_blog(fresh=False, report_total_errors=True):
failed_builds += 1
sys.stderr.write("error: failed to generate %s" %
relpath)
+ number_code_lines(dstpath)
+
if anything_modified:
generate_index_and_feed()
+ sys.stderr.write("done\n")
if report_total_errors:
sys.stderr.write("build finished with %d errors\n" % failed_builds)
diff --git a/source/blog/2014-12-23-mpv-launcher.md b/source/blog/2014-12-23-mpv-launcher.md
index bc4710e5..c8c2aee2 100644
--- a/source/blog/2014-12-23-mpv-launcher.md
+++ b/source/blog/2014-12-23-mpv-launcher.md
@@ -7,7 +7,9 @@ date-display: December 23, 2014
I just noticed that `daemonize` doesn't play too well with the OS; in particular, when you use dark menu bar on OS X Yosemite, apps launched with `daemonize` won't conform to that. So a native shell solution would be using `/bin/zsh` and run
- mpv "$@" >/dev/null 2>&1 </dev/null &!
+```zsh
+mpv "$@" >/dev/null 2>&1 </dev/null &!
+```
instead.
@@ -17,7 +19,9 @@ instead.
Today I finally gave this issue some serious thought (I've been on a bug report/enhancement request spree these days so it's natural for me to start thinking about enhancements). Turns out that there's a pretty simple workaround. I created an automator app `mpv-launcher.app` that does one thing: "Run Shell Script" (pass input as arguments)
- daemonize /usr/local/bin/mpv "$@"
+```bash
+daemonize /usr/local/bin/mpv "$@"
+```
in the shell of your choice (for me the shell of choice is `zsh` since the env would be readily available from my `zshenv`). `daemonize`, as the name suggests, daemonizes the process so that the process doesn't block; this way, `mpv-launcher.app` immediately quits after launching, making multiple "instances" possible. (`daemonize` can be installed via `brew install daemonize`; note that you need to specify the full path of the command to daemonize, which in my case is `/usr/local/bin/mpv`). And there you go. Associate your video files to `mpv-launcher.app`. Launch as many instances as you want. Enjoy.
diff --git a/source/blog/2015-02-24-the-new-onedrive-api.md b/source/blog/2015-02-24-the-new-onedrive-api.md
index 9a74d89f..1a973d58 100644
--- a/source/blog/2015-02-24-the-new-onedrive-api.md
+++ b/source/blog/2015-02-24-the-new-onedrive-api.md
@@ -3,6 +3,6 @@ title: "The new OneDrive API"
date: 2015-02-24T18:31:19-0800
date-display: February 24, 2015
---
-Microsoft released the new OneDrive API today. See the blog post announcement [here](https://blog.onedrive.com/the-new-onedrive-api/). One highlight is that [large file upload](http://onedrive.github.io/items/upload_large_files.htm) is now officially supported. Previously, large file upload was handled with a semi-official API using the BITS protocol; the only documentation was a [gist](https://gist.github.com/rgregg/37ba8929768a62131e85). Now it is handled through standard HTTP `POST`. With this major release, there's likely a lot of work to be done with [python-onedrive](https://github.com/mk-fg/python-onedrive). I have opened an issue: `mk-fg/python-onedrive#52` — [New OneDrive API support](https://github.com/mk-fg/python-onedrive/issues/52).
+Microsoft released the new OneDrive API today. See the blog post announcement [here](https://blog.onedrive.com/the-new-onedrive-api/). One highlight is that [large file upload](http://onedrive.github.io/items/upload_large_files.htm) is now officially supported. Previously, large file upload was handled with a semi-official API using the BITS protocol; the only documentation was a [gist](https://gist.github.com/rgregg/37ba8929768a62131e85). Now it is handled through standard HTTP `POST`. With this major release, there's likely a lot of work to be done with [python-onedrive](https://github.com/mk-fg/python-onedrive). I have opened an issue: [mk-fg/python-onedrive#52 — New OneDrive API support](https://github.com/mk-fg/python-onedrive/issues/52).
Interestingly, the new OneDrive API doc is hosted on GitHub Pages — [onedrive.github.io](http://onedrive.github.io), rather than MSDN. Exactly a week ago I wrote a piece, "[Microsoft is getting cool (but not its website)](/blog/2015-02-17-microsoft-is-getting-cool-but-not-its-website.html)". Looks like they are doing something about their website (or better put, their online identity), too.
diff --git a/source/blog/2015-04-26-using-python-3-with-emacs-jedi.md b/source/blog/2015-04-26-using-python-3-with-emacs-jedi.md
index 5171d584..1d95f506 100644
--- a/source/blog/2015-04-26-using-python-3-with-emacs-jedi.md
+++ b/source/blog/2015-04-26-using-python-3-with-emacs-jedi.md
@@ -18,7 +18,7 @@ virtualenv -p /usr/local/bin/python3 ~/.emacs.d/.python-environments/jedi # or
And that's it. Put the following in your `~/.emacs`:
-```emacs-lisp
+```commonlisp
(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:complete-on-dot t)
(setq jedi:environment-root "jedi")
diff --git a/source/css/theme.css b/source/css/theme.css
index 19930c0f..7d140c80 100644
--- a/source/css/theme.css
+++ b/source/css/theme.css
@@ -51,16 +51,45 @@ h3 {
}
code {
- font-family: 'Courier', monospace;
- font-size: 10.5pt;
+ font-family: 'Consolas', 'Monaco', 'Andale Mono', 'Courier', monospace;
+ font-weight: thin;
}
pre {
- margin: 0 2em;
+ padding: 1em;
+ background: #fbfbfb;
+ border-left: 0.4em solid #ddd;
+}
+
+pre[class*=sourceCode] {
+ position: relative;
+ padding-left: 2em;
+ margin: 0;
}
pre code {
- font-size: 10pt;
+ font-size: 10.5pt;
+}
+
+.line-number {
+ position: absolute;
+ left: 0;
+ right: 0;
+ margin-top: 1em;
+ pointer-events: none;
+ white-space: pre;
+}
+
+.line-number:before {
+ content: attr(data-line);
+ position: absolute;
+ top: .4em;
+ left: .5em;
+ min-width: 2em;
+ color: #ccc;
+ font: 500 65%/1.5 sans-serif;
+ text-align: center;
+ vertical-align: .3em;
}
blockquote {
@@ -72,10 +101,6 @@ div.footnotes {
font-size: 10pt;
}
-div.footnotes code {
- font-size: 9.5pt;
-}
-
img {
display: block;
max-width: 100%;
diff --git a/source/key.md b/source/key.md
index 21a58bdf..f425f537 100644
--- a/source/key.md
+++ b/source/key.md
@@ -58,6 +58,5 @@ DfzWWr45PX+1JO3v2syPqeVn4O8FVg74JMiNLjcMR7p1iNSIAC+RQTIa9Z8YvS8S
HNSeBk1A1wT9lfQ/V6nzcu+p2jdc2PjDop/eprGQbJuIqN38mhmjABMhtsvbgs5d
01Ii48sdMukeqyHXqz5FQlyLxnlMtfUbhtw55OJHBsY0Brgv
=0NyM
------END PGP PUBLIC KEY BLOCK-----
-</code>
+-----END PGP PUBLIC KEY BLOCK-----</code>
</pre>
diff --git a/templates/template.html b/templates/template.html
index 08bb34f1..9e6efc0f 100644
--- a/templates/template.html
+++ b/templates/template.html
@@ -1,16 +1,16 @@
<!DOCTYPE html>
<html>
<head>
-<meta charset="UTF-8">
-<meta name="generator" content="pandoc" />
-<meta name="author" content="Zhiming Wang" />
+<meta charset="UTF-8"/>
+<meta name="generator" content="pandoc"/>
+<meta name="author" content="Zhiming Wang"/>
$if(date)$
-<meta name="date" content="$date$" />
+<meta name="date" content="$date$"/>
$endif$
<title>$pagetitle$</title>
-<link rel="apple-touch-icon-precomposed" href="/img/favicon-152.png">
-<meta name="msapplication-TileColor" content="#FFFFFF">
-<meta name="msapplication-TileImage" content="/img/favicon-144.png">
+<link rel="apple-touch-icon-precomposed" href="/img/favicon-152.png"/>
+<meta name="msapplication-TileColor" content="#FFFFFF"/>
+<meta name="msapplication-TileImage" content="/img/favicon-144.png"/>
<style type="text/css">code{white-space: pre;}</style>
$if(quotes)$
<style type="text/css">q { quotes: "“" "”" "‘" "’"; }</style>
@@ -29,9 +29,9 @@ $endif$
$for(header-includes)$
$header-includes$
$endfor$
-<link href='/css/normalize.css' media="all" rel="stylesheet" type="text/css">
-<link href='/css/theme.css' media="all" rel="stylesheet" type="text/css">
-<link href="//fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
+<link href='/css/normalize.css' media="all" rel="stylesheet" type="text/css"/>
+<link href='/css/theme.css' media="all" rel="stylesheet" type="text/css"/>
+<link href="//fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css"/>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@@ -72,7 +72,7 @@ $toc$
$endif$
$body$
<footer>
-<hr>
+<hr/>
$if(updated)$
<span class="lfooter">
<time class="updated" datetime="$updated$"><code>$updated$</code></time>