在 Linux 系統中,使用 asciidoc 自動化生成文檔可以通過以下幾個步驟實現:
安裝 asciidoc:
對于基于 Debian 的系統(如 Ubuntu),使用以下命令安裝:
sudo apt-get install asciidoc
對于基于 RHEL 的系統(如 CentOS、Fedora),使用以下命令安裝:
sudo yum install asciidoc
創建一個 asciidoc 文件:
使用文本編輯器創建一個新的 asciidoc 文件,例如 example.adoc
。在這個文件中,編寫你的文檔內容,使用 asciidoc 語法。例如:
= Example Document
:toc:
Introduction
=======
This is an example document generated by Asciidoc.
添加一個腳本以自動化生成 PDF 和 HTML 文件:
在 asciidoc 文件所在的目錄中,創建一個名為 generate_docs.sh
的腳本文件,并添加以下內容:
#!/bin/bash
# Convert Asciidoc file to HTML
asciidoc -a stylesheet=style.css example.adoc -o example.html
# Convert Asciidoc file to PDF
asciidoc -a stylesheet=style.css -o example.pdf example.adoc
echo "Documentation generated successfully!"
這個腳本將使用 asciidoc 命令將 .adoc
文件轉換為 .html
和 .pdf
文件。確保你的系統中已經安裝了 asciidoc
命令。
使腳本可執行:
在終端中,導航到腳本所在的目錄,然后運行以下命令使腳本可執行:
chmod +x generate_docs.sh
運行腳本生成文檔:
現在,你可以通過運行以下命令來自動化生成 HTML 和 PDF 文件:
./generate_docs.sh
這將在同一目錄下生成 example.html
和 example.pdf
文件。你可以根據需要修改腳本以適應你的項目結構和需求。