从一个json文件制作许多markdown文件的脚本将在http:和https:前缀中添加回链接。为什么?

时间:2019-04-10 18:24:03

标签: javascript node.js json markdown

我有一个大的json文件,该文件使用gatsby.js(对问题不重要)和markdown(重要)填充问题。我的数据看起来像这样。

"-JugHeFMJfGN071lmqqo" : {
      "askedHistPercent1" : "58",
      "askedHistPercent2" : "54",
      "askedHistYear1" : "2018",
      "askedHistYear2" : "2015",
      "author" : "Author Name",
      "categories" : [ "Category 1", "Cat 2", "Cat 3" ],
      "date" : "2015-07-20 09:27:29",
      "definition" : "Long Definition here. Includes a now //link to show the content. Was a http://link or https://link before I deleted all the link prefixes with control-f replace",
      "permalink" : "//www.Urlherelong",
      "title" : "Title here"
    }, 


etc,此.json文件中还有1600个项目。我已经构建了以下脚本,将所有信息作为yaml frontmatter放入markdown文件中,以便与gatsby graphql一起使用。它看起来不漂亮,但是有99.99%的时间可以工作

const fs = require("fs");
const YAML = require("yamljs");
const bigObject = require("../1111data.json");
var _ = require("lodash");

Object.entries(bigObject).forEach(([name, data]) => {
  fs.writeFile(`${_.kebabCase(data.title)}.md`, "---\r\n", err => {
    fs.appendFile(`${_.kebabCase(data.title)}.md`,YAML.stringify(data),
      err => {
        fs.appendFile(`${_.kebabCase(data.title)}.md`, "\r\n---\r\n", err => {

          if (err) throw err;
          console.log(`${_.kebabCase(data.title)}.md has been saved!`);

        });
      }
    );
  });
});

无论如何,脚本会将http和https前缀放回我的URL链接中。我团队中的资深开发人员希望我在所有网址上都添加//前缀。从我的.json文件poof中删除所有https:和http:之后,它们会重新显示。我坐在这里挠头,因为我从未告诉过他们这样做。您会认为脚本将是100%提取的信息,对不对?这就是我得到的。

---
askedHistPercent1: "35"
askedHistYear1: "2008"
assocMediaLink1: ""
author: ""
categories:
  - category1
content: ""
date: "2015-03-05 17:01:55"
definition: "http://link here again. Rest of definition"
excerpt: "yada yada"
id: 14247
permalink: "http://link"
title: "title"
---

我可以在脚本中添加一些内容来阻止重新添加http和https链接前缀,并保留//www.etc吗?

0 个答案:

没有答案