Skip to content

Commit

Permalink
[skip ci] rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
theowenyoung committed Oct 29, 2022
1 parent bea0634 commit 2660054
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions build-by-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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}`;
Expand All @@ -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(),
Expand Down
14 changes: 14 additions & 0 deletions build-by-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
SUBSCRIPTION_URL,
} from "./constant.ts";
import {
formatHumanTime,
getBaseFeed,
getDistRepoContentPath,
getDomain,
Expand Down Expand Up @@ -214,6 +215,7 @@ export function itemsToFeedItems(

let groupMarkdown = "";
let groupHtml = "";
let summary = "";

const categoryGroup = groupBy(items, "category") as Record<
string,
Expand All @@ -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) {
Expand All @@ -240,6 +243,7 @@ export function itemsToFeedItems(
groupMarkdown += `\n`;
}
categoryGroup[key].forEach((item) => {
total++;
groupMarkdown += "\n" + item.markdown;
groupHtml += item.html;
firstItem = item;
Expand All @@ -252,6 +256,7 @@ export function itemsToFeedItems(
}
});
});
summary = `${total} awesome projects updated`;
if (!firstItem) {
throw new Error(`${key} has no firstItem`);
}
Expand All @@ -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(),
Expand Down Expand Up @@ -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)
})`;
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
);
Expand Down
3 changes: 3 additions & 0 deletions interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export interface CliOptions {
fetchRepoUpdates: boolean;
markdown: boolean;
fetch: boolean;
cleanMarkdown?: boolean;
cleanHtml?: boolean;
dayMarkdown: boolean;
rebuild?: boolean;
html?: boolean;
Expand Down Expand Up @@ -256,6 +258,7 @@ export interface FeedItem {
url: string;
_slug: string;
_filepath: string;
summary: string;
date_published: string;
date_modified: string;
tags?: string[];
Expand Down
2 changes: 2 additions & 0 deletions tal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down

0 comments on commit 2660054

Please sign in to comment.