学校为每个研究者提供一个空间,用于存放个人学术主页,但只能是静态页面。搜了一下,没找到自己满意的模板。后来就想,用markdown编辑好,再转换成html。事实上,这样做还有一个好处,主页可以在不同设备上显示得很好。动手弄了一个,效果还不错,欢迎围观:Qiankun SU at INP-ENSEEIHT

1. 使用Python

使用pypandoc,示例代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pypandoc

# With an input file: it will infer the input format from the filename
output = pypandoc.convert_file('index.md', 'html', outputfile='index-2.html')

这样做,只是简单地将markdown转换成html,我的markdown文档包含一些法语字符,不能正常显示,需要手动在html文件指定字符编码,即在html文件头部添加如下一行:

encoding = '<meta charset="utf-8">'

2. 使用命令行

直接在命令行使用pandoc命令,使用-s选项为输出文档添加header和footer,举例如下:

# An example 
pandoc -f markdown index.md -t html -Ss > index.html

# Parameters
-f format
Specify input format

-t format
Specify output format

-S, --smart
Produce typographically correct output, converting straight quotes to curly quotes, --- to em-dashes, -- to en-dashes, and ... to  ellipses. Nonbreaking spaces are inserted after certain abbreviations, such as "Mr."

-s, --standalone
Produce output with an appropriate header and footer (e.g.  a standalone HTML, LaTeX, TEI, or RTF file, not a fragment). This option is set automatically for pdf, epub, epub3, fb2, docx, and odt output.

这样就会在生成的html文档添加如下内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <link rel="icon" href="logo_inpt.png">
  <title>Qiankun SU at INP-ENSEEIHT</title> 
  <style type="text/css">code{white-space: pre;}</style>
</head>
<body>
....
</body>
</html>

再自己手动添加title和icon,举例如下:

<link rel="icon" href="logo_inpt.png">
<title>Qiankun SU at INP-ENSEEIHT</title>

3. 转换bibtex

比如我一篇论文的bibtex如下:

@INPROCEEDINGS{su2015xor, 
author={Q. Su and K. Jaffres-Runser and G. Jakllari and C. Poulliat}, 
booktitle={2015 IEEE/CIC International Conference on Communications in China (ICCC)}, 
title={XOR network coding for data mule delay tolerant networks}, 
year={2015}, 
pages={1-6}, 
keywords={Base stations;Delays;Network coding;Protocols;TV;Throughput;Urban areas;Delay tolerant networks;XOR;data mules;network coding;village communication networks}, 
doi={10.1109/ICCChina.2015.7448634}, 
month={Nov},}

用上述的方法转换得到的html,得到的是一行,可读性差。使用hard_line_breaks选项,把段落内的newlines转换成换行,而不是空格,举例如下:

pandoc -f markdown+hard_line_breaks MSWiM16.md -t html -Ss > MSWiM16.html

# hard_line_breaks
Extension: hard_line_breaks
Causes all newlines within a paragraph to be interpreted as hard line breaks instead of spaces.

4. 上传到服务器

把做好的html打包,用scp上传到服务器,举例如下:

qsu@pc-irt18:~/Téléchargements$ scp su_homepage.tar.gz qsu@su.perso.enseeiht.fr:/var/www/su.perso
qsu@su.perso.enseeiht.fr's password: 
su_homepage.tar.gz                             100% 9475KB   9.3MB/s   00:00

登录到服务器,解压就可以了,举例如下:

ssh ​su.perso.enseeiht.fr

至此,一个简洁的个人学术主页就有了:-)

5. 更简单的方法

最近转到GitBook,把之前的系列博文整理成书,再给众多合集做个目录,用Markdown做一个简单的页面。

使用Markdown编辑器Typora,文件 --> 导出 --> HTML。额外弄一个css文件,给网站内容格式做一些微调,并把css文件加入到Markdown文档开始处:

<link rel="stylesheet" type="text/css" href="style.css">

最后的效果,见博文合集

本文系Spark & Shine原创,转载需注明出处本文最近一次修改时间 2022-04-17 10:51

results matching ""

    No results matching ""