mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-28 17:57:48 +02:00
* Merge fix * Updating lock file. * Bug fix for rss feed truncation... * Fixes infinite recursive loop for #89 * Removed use of module cache invalidator from feed.js * Replaced 'latest' babel presets with 'env' * Ignore temp build folder * Adding back new truncation logic for RSS * Updating yarn lock
83 lines
2.2 KiB
JavaScript
83 lines
2.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2017-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
const fs = require("fs-extra");
|
|
const path = require("path");
|
|
const os = require("os");
|
|
const Feed = require("feed");
|
|
|
|
const chalk = require("chalk");
|
|
const CWD = process.cwd();
|
|
|
|
const siteConfig = require(CWD + "/siteConfig.js");
|
|
|
|
const blogFolder = path.resolve("../blog/");
|
|
const blogRootURL = siteConfig.url + "/blog";
|
|
const jestImage = siteConfig.url + siteConfig.headerIcon;
|
|
|
|
/****************************************************************************/
|
|
|
|
let readMetadata;
|
|
let Metadata;
|
|
|
|
readMetadata = require("./readMetadata.js");
|
|
readMetadata.generateDocsMetadata();
|
|
Metadata = require("../core/metadata.js");
|
|
|
|
/****************************************************************************/
|
|
|
|
module.exports = function(type) {
|
|
console.log("feed.js triggered...");
|
|
|
|
type = type || "rss";
|
|
|
|
readMetadata.generateBlogMetadata();
|
|
const MetadataBlog = require("../core/MetadataBlog.js");
|
|
|
|
const feed = new Feed({
|
|
title: siteConfig.title + " Blog",
|
|
description:
|
|
"The best place to stay up-to-date with the latest " +
|
|
siteConfig.title +
|
|
" news and events.",
|
|
id: blogRootURL,
|
|
link: blogRootURL,
|
|
image: jestImage,
|
|
copyright: siteConfig.copyright,
|
|
updated: new Date(MetadataBlog[0].date)
|
|
});
|
|
|
|
MetadataBlog.forEach(post => {
|
|
const url = blogRootURL + "/" + post.path;
|
|
let content = "";
|
|
if (post.content.indexOf("<!--truncate-->") == -1) {
|
|
content = post.content.trim().substring(0, 250);
|
|
} else {
|
|
let contentArr = post.content.split("<!--truncate-->");
|
|
if (contentArr.length > 0) {
|
|
content = contentArr[0];
|
|
}
|
|
}
|
|
|
|
feed.addItem({
|
|
title: post.title,
|
|
link: url,
|
|
author: [
|
|
{
|
|
name: post.author,
|
|
link: post.authorURL
|
|
}
|
|
],
|
|
date: new Date(post.date),
|
|
description: content
|
|
});
|
|
});
|
|
|
|
return type === "rss" ? feed.rss2() : feed.atom1();
|
|
};
|