美文网首页
Jekyll 将csv文件转换为html静态文件展示

Jekyll 将csv文件转换为html静态文件展示

作者: 偷油考拉 | 来源:发表于2021-09-13 16:42 被阅读0次

    需求:
    公司将对各个环境域名-IP的映射关系展示给开发人员,这些是不定期、以csv文件更新的。
    编程时间长,维护略困难;计划通过Jekyll框架的_data目录将csv文件转换为html的方式进行展示。

    csv 范例:

    num,system,sub_domain,domain_name,description,SIT,UAT,STA,PRD
    1,root,.,dns,只存在一台DNS,10.41.100.3,,,
    2,root,.,dns1,DNS Primay,,10.51.100.6,,
    3,root,.,dns2,DNS Slave,,10.51.100.8,,
    4,通用服务,common,zk.common,zookeeper_单机地址,10.41.100.31,,,
    5,通用服务,common,zk1.common,zookeeper_服务器1地址,10.41.100.31,10.51.100.11,,
    6,通用服务,common,zk2.common,zookeeper_服务器2地址,,10.51.100.12,,
    7,通用服务,common,zk3.common,zookeeper_服务器3地址,,10.51.100.13,,
    8,通用服务,common,zk4.common,zookeeper_服务器4地址,,10.51.100.14,,
    9,通用服务,common,zk5.common,zookeeper_服务器5地址,,10.51.100.15,,
    10,通用服务,common,amq.common,activemq_单机地址,10.41.100.34,,,
    

    Jekyll 实现

    1. 将csv文件上传到_data目录
    [jekyll@VM_1_5_centos _data]$ pwd
    /home/jekyll/myblog/_data
    [jekyll@VM_1_5_centos _data]$ ls
    dns.csv
    
    1. 编写展示dnslist.html,位于_data/的上级目录
    ---
    layout: home
    ---
    
    <h1>DNS List</h1>
    
    
    <table cellpadding="0" cellspacing="0" style="table-layout: fixed;word-break: break-all; word-wrap: break-word;">
      <tr>
        <th width="100">系统</th>
        <th width="100" >子域</th>
        <th width="100">域名</th>
        <th width="150">描述</th>
        <th width="150">SIT</th>
        <th width="150">UAT</th>
        <th width="150">STA</th>
        <th width="150">PRD</th>
      </tr>
      {% for member in site.data.dns %}
      <tr>
        <td>{{ member.system }}</td>
        <td>{{ member.sub_domain }}</td>
        <td>{{ member.domain_name }}</td>
        <td>{{ member.description }}</td>
        <td>{{ member.SIT }}</td>
        <td>{{ member.UAT }}</td>
        <td>{{ member.STA }}</td>
        <td>{{ member.PRD }}</td>
      </tr>
      {% endfor %}
    </table>
    
    1. 执行jekyll server启动服务器,会将静态文件生成于_site目录,文件名 dnslist.html。
    [jekyll@VM_1_5_centos myblog]$ ls _site/
    404.html  about  assets  dns.html  dnslist.html  favicon.ico  feed.xml  index.html  jekyll
    

    相关文章

      网友评论

          本文标题:Jekyll 将csv文件转换为html静态文件展示

          本文链接:https://www.haomeiwen.com/subject/tjyfgltx.html