Skip to content

Commit

Permalink
Merge pull request #54 from ega4432/feature/create-files-count#52
Browse files Browse the repository at this point in the history
Output exported count
  • Loading branch information
ega4432 authored Feb 25, 2023
2 parents 3103bee + f24be90 commit 1ebbb72
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ jobs:
steps:
- name: Checkout source
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Normal test
id: import
uses: ./
env:
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
Expand All @@ -41,6 +40,7 @@ jobs:
ACTIONS_RUNNER_DEBUG: true

- name: Specific property as a markdown filename
id: import2
uses: ./
with:
filename_property: 'slug'
Expand All @@ -49,3 +49,8 @@ jobs:
NOTION_DATABASE_ID: ${{ secrets.NOTION_DATABASE_ID }}
ACTIONS_STEP_DEBUG: true
ACTIONS_RUNNER_DEBUG: true

- name: Check output
run: |
echo "Normal test: exported count: ${{ steps.import.outputs.files_count }}"
echo "Specified property test: exported count: ${{ steps.import2.outputs.files_count }}"
12 changes: 9 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { getInput, setFailed, info, error } from '@actions/core';
import {
getInput,
setFailed,
info,
error,
setOutput,
debug
} from '@actions/core';
import { mkdirP } from '@actions/io';
import { Client } from '@notionhq/client';
import { writeFile } from 'fs/promises';
import { readdir, writeFile } from 'fs/promises';
import get from 'axios';

import { queryDatabase } from './utils/notion';
Expand Down Expand Up @@ -46,17 +53,23 @@ const run = async (

await createFiles(mdResponse, outDir);

const files = await readdir(outDir);
debug(`Output: files_count=${files.length.toString()}`);
setOutput('files_count', files.length.toString());

info('---> Successfully created markdown files!');
};

const createFiles = async (pages: MarkdownPage[], outDir: string) => {
for (const markdown of pages) {
pages.forEach(async (markdown) => {
if (markdown.filename.length) {
// NOTE: 現状すでにファイルが存在していても上書きする
await writeFile(`${outDir}/${markdown.filename}.md`, markdown.body);
const filename = `${outDir}/${markdown.filename}.md`;
await writeFile(filename, markdown.body);
debug(`Created: ${filename}`);
await downloadImages(markdown.filename, outDir);
}
}
});
};

const downloadImages = async (filename: string, outDir: string) => {
Expand All @@ -73,6 +86,8 @@ const downloadImages = async (filename: string, outDir: string) => {
const image = `${filename}/${alt || `untitled${untitledCount}`}.png`;
await writeFile(`${outDir}/${image}`, res.data, 'binary');

debug(`Created image: ${outDir}/${image}`);

replaced = replaced.replace(src, image);
}

Expand Down

0 comments on commit 1ebbb72

Please sign in to comment.