fix: template cannot be loaded from ejs file

This commit is contained in:
Simone Corsi
2021-01-16 11:42:06 +01:00
parent 91de25f5dc
commit 78c0f37ebe
2 changed files with 7 additions and 6 deletions

View File

@@ -2,11 +2,12 @@ import fs from 'fs';
import ejs from 'ejs';
import remark from 'remark';
import toc from 'remark-toc';
import * as core from '@actions/core';
import GithubApi from './api';
import link from './link';
import git from './git';
import * as core from '@actions/core';
import path from 'path';
import MD_TEMPLATE from './template';
import type {
SortedLanguageList,
@@ -22,10 +23,9 @@ const OUTPUT_FILENAME: string = core.getInput('output-filename') || 'README.md';
const REPO_USERNAME = process.env.GITHUB_REPOSITORY?.split('/')[0];
const API_STARRED_URL = `${process.env.GITHUB_API_URL}/users/${REPO_USERNAME}/starred`;
const renderer = async (data: any) => {
const renderer = async (data: any, templateString = MD_TEMPLATE) => {
try {
const MD_TEMPLATE = await fsp.readFile('./template.ejs', 'utf-8');
return ejs.render(MD_TEMPLATE, data);
return ejs.render(templateString, data);
} catch (error) {
core.error('#renderer');
core.error(error);

View File

@@ -1,4 +1,4 @@
# <%= username %> Awesome List [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)
export default `# <%= username %> Awesome List [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)
## Table of Contents
@@ -9,3 +9,4 @@
<% } %>
<% } %>
`;