diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 86c245b..74b47a8 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -95,7 +95,7 @@ jobs: # name: temp # path: temp # if-no-files-found: ignore - - name: throw if source failed + - name: throw if build failed if: steps.source.outcome == 'failure' run: | echo "::error::prod-build failed" diff --git a/Makefile b/Makefile index 99ce52e..bdcc69c 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ prod-start: FORCE=1 PROD=1 deno run -A tal.ts ${args} .Phony: prod-builddemo prod-builddemo: - FORCE=1 PROD=1 deno run -A tal.ts --no-fetch --html ripienaar/free-for-dev + FORCE=1 PROD=1 deno run -A tal.ts --no-fetch --html ripienaar/free-for-dev ${args} .Phony: prod-buildindex prod-buildindex: PROD=1 deno run -A tal.ts --no-fetch --html ripienaar/free-for-dev diff --git a/build-by-source.ts b/build-by-source.ts index 7d76992..615d85a 100644 --- a/build-by-source.ts +++ b/build-by-source.ts @@ -200,12 +200,14 @@ export default async function main( >; let groupMarkdown = ""; let groupHtml = ""; + let summary = ""; const categoryKeys: string[] = Object.keys(categoryGroup); const today = new Date(); const tomorrow = new Date(today); tomorrow.setDate(tomorrow.getDate() + 1); let datePublished: Date = tomorrow; let dateModified: Date = new Date(0); + let total = 0; categoryKeys.forEach((key: string) => { const categoryItem = categoryGroup[key][0]; if (key) { @@ -215,6 +217,7 @@ export default async function main( groupMarkdown += `\n`; } categoryGroup[key].forEach((item) => { + total++; groupMarkdown += `\n${item.markdown}`; groupHtml += `\n${item.html}`; const itemUpdatedAt = new Date(item.updated_at); @@ -232,6 +235,7 @@ export default async function main( } else { dayInfo = parseWeekInfo(Number(key)); } + summary = `${total} awesome projects updated on ${dayInfo.name}`; const slug = dayInfo.path + "/"; const itemUrl = `${domain}/${dayInfo.path}/`; const url = `${domain}/${slug}`; @@ -240,6 +244,7 @@ export default async function main( title: `${fileConfig.name} Updates on ${dayInfo.name}`, _short_title: dayInfo.name, _slug: slug, + summary, _filepath: pathnameToFilePath("/" + slug), url: itemUrl, date_published: datePublished.toISOString(), diff --git a/build-by-time.ts b/build-by-time.ts index 6aba244..7f70ceb 100644 --- a/build-by-time.ts +++ b/build-by-time.ts @@ -21,6 +21,7 @@ import { SUBSCRIPTION_URL, } from "./constant.ts"; import { + formatHumanTime, getBaseFeed, getDistRepoContentPath, getDomain, @@ -214,6 +215,7 @@ export function itemsToFeedItems( let groupMarkdown = ""; let groupHtml = ""; + let summary = ""; const categoryGroup = groupBy(items, "category") as Record< string, @@ -231,6 +233,7 @@ export function itemsToFeedItems( tomorrow.setDate(tomorrow.getDate() + 1); let datePublished: Date = tomorrow; let dateModified: Date = new Date(0); + let total = 0; categoryKeys.forEach((key) => { const categoryItem = categoryGroup[key][0]; if (key) { @@ -240,6 +243,7 @@ export function itemsToFeedItems( groupMarkdown += `\n`; } categoryGroup[key].forEach((item) => { + total++; groupMarkdown += "\n" + item.markdown; groupHtml += item.html; firstItem = item; @@ -252,6 +256,7 @@ export function itemsToFeedItems( } }); }); + summary = `${total} awesome projects updated`; if (!firstItem) { throw new Error(`${key} has no firstItem`); } @@ -270,6 +275,7 @@ export function itemsToFeedItems( _slug: slug, _filepath: pathnameToFilePath("/" + slug), url: itemUrl, + summary: summary, content_text: groupMarkdown, content_html: groupHtml, date_published: datePublished.toISOString(), @@ -332,10 +338,16 @@ export function itemsToFeedItemsByDate( tomorrow.setDate(tomorrow.getDate() + 1); let datePublished: Date = tomorrow; let dateModified: Date = new Date(0); + let total = 0; + let summary = "including "; categoryKeys.forEach((key, index) => { const firstSourceItem = categoryGroup[key][0]; const sourceFileConfig = sourcesConfig[firstSourceItem.source_identifier] .files[firstSourceItem.file]; + total++; + summary += `${sourceFileConfig.name}${ + index < categoryKeys.length - 1 ? ", " : "" + }`; groupMarkdown += `\n\n#### [${index + 1}. ${sourceFileConfig.name}](${ pathnameToFilePath(sourceFileConfig.pathname) })`; @@ -385,11 +397,13 @@ export function itemsToFeedItemsByDate( : parseWeekInfo(Number(key)); const slug = dayInfo.path + "/"; const itemUrl = `${domain}/${slug}`; + summary = `${total} awesome list updated on ${dayInfo.name}, ` + summary; const feedItem: FeedItem = { id: itemUrl, title: `Awesome List Updated on ${dayInfo.name}`, _short_title: dayInfo.name, _slug: slug, + summary, _filepath: pathnameToFilePath("/" + slug), url: itemUrl, content_text: groupMarkdown, diff --git a/build.ts b/build.ts index 2c375de..f9b600c 100644 --- a/build.ts +++ b/build.ts @@ -70,6 +70,7 @@ export default async function buildMarkdown(options: RunOptions) { log.info("skip build site or markdown"); return; } + const dbMeta = await getDbMeta(); const dbIndex = await getDbIndex(); const dbSources = dbMeta.sources; @@ -182,6 +183,29 @@ export default async function buildMarkdown(options: RunOptions) { await p.status(); } } + + if (options.cleanMarkdown) { + log.info("clean markdown files"); + // remove all dist repo path files, except .git + const walker = await fs.walk(distRepoPath); + for await (const entry of walker) { + const relativePath = path.relative(distRepoPath, entry.path); + if (relativePath.startsWith(".git")) { + continue; + } else { + await Deno.remove(entry.path, { + recursive: true, + }); + } + } + } + if (options.cleanHtml) { + log.info("clean html files"); + // remove all dist repo path files, except .git + await Deno.remove(getPublicPath(), { + recursive: true, + }); + } const rootTemplateContent = await readTextFile( "./templates/root-readme.md.mu", ); diff --git a/interface.ts b/interface.ts index 266f414..ca34dd8 100644 --- a/interface.ts +++ b/interface.ts @@ -144,6 +144,8 @@ export interface CliOptions { fetchRepoUpdates: boolean; markdown: boolean; fetch: boolean; + cleanMarkdown?: boolean; + cleanHtml?: boolean; dayMarkdown: boolean; rebuild?: boolean; html?: boolean; @@ -256,6 +258,7 @@ export interface FeedItem { url: string; _slug: string; _filepath: string; + summary: string; date_published: string; date_modified: string; tags?: string[]; diff --git a/tal.ts b/tal.ts index c90ce38..7f82929 100644 --- a/tal.ts +++ b/tal.ts @@ -23,6 +23,8 @@ export default async function tal() { .option("-p, --push", "Push markdown to remote.") .option("--no-fetch", "Don't fetch remote sources.") .option("--no-markdown", "do not build markdown file.") + .option("--clean-html", "clean html files.") + .option("--clean-markdown", "clean markdown files.") .option("--no-day-markdown", "do not build day markdown file.") .option("--no-fetch-repo-updates", "do not fetch repo updates.") .option("--html", "Build html files.")