Skip to content

Commit

Permalink
fix: add lowercase, uppercase and uppercasefirst to the function map …
Browse files Browse the repository at this point in the history
…in the template
  • Loading branch information
sywhb committed May 12, 2023
1 parent 26572b6 commit 957bbca
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/settings/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import {
siteNameFromUrl,
} from "../util";

type FunctionMap = {
[key: string]: () => (
text: string,
render: (text: string) => string
) => string;
};

export const DEFAULT_TEMPLATE = `---
id: {{{id}}}
title: >
Expand Down Expand Up @@ -59,7 +66,8 @@ export interface HighlightView {
labels?: LabelView[];
}

export interface ArticleView {
export type ArticleView =
| {
id: string;
title: string;
omnivoreUrl: string;
Expand All @@ -79,6 +87,9 @@ export interface ArticleView {
wordsCount?: number;
readLength?: number;
state: string;
}
| FunctionMap;

enum ArticleState {
Inbox = "INBOX",
Reading = "READING",
Expand All @@ -99,6 +110,31 @@ const getArticleState = (article: Article): string => {
return ArticleState.Inbox;
};

function lowerCase() {
return function (text: string, render: (text: string) => string) {
return render(text).toLowerCase();
};
}

function upperCase() {
return function (text: string, render: (text: string) => string) {
return render(text).toUpperCase();
};
}

function upperCaseFirst() {
return function (text: string, render: (text: string) => string) {
const str = render(text);
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
};
}

const functionMap: FunctionMap = {
lowerCase,
upperCase,
upperCaseFirst,
};

export const renderFilename = (
article: Article,
filename: string,
Expand Down Expand Up @@ -214,6 +250,7 @@ export const renderArticleContnet = async (
wordsCount,
readLength,
state: getArticleState(article),
...functionMap,
};
// Build content string based on template
let content = Mustache.render(template, articleView);
Expand Down

0 comments on commit 957bbca

Please sign in to comment.