Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 04ae2ee

Browse files
committed
Added support for custom base64 encoded svg logo
1 parent fd8c33f commit 04ae2ee

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

‎src/action.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,20 @@ export async function action() {
7171
core.info('Fetched rows');
7272
const { schema } = collection;
7373
const [
74-
category_schema_entry,
75-
color_schema_entry
74+
categorySchemaEntry,
75+
colorSchemaEntry,
76+
,
77+
base64SchemaEntry
7678
] = ActionUtils.getSchemaEntries(schema);
7779

7880
const rows = ActionUtils.modifyRows(recordMap, databaseId);
79-
const categories_map = ActionUtils.constructCategoriesMap(
80-
category_schema_entry[1]
81+
const categoriesMap = ActionUtils.constructCategoriesMap(
82+
categorySchemaEntry[1]
8183
);
8284
ActionUtils.populateCategoriesMapItems(
8385
rows,
84-
category_schema_entry[0],
85-
categories_map
86+
categorySchemaEntry[0],
87+
categoriesMap
8688
);
8789

8890
const README_PATH = `${process.env.GITHUB_WORKSPACE}/README.md`;
@@ -92,8 +94,9 @@ export async function action() {
9294

9395
const [startIdx, endIdx] = ActionUtils.checkForSections(readmeLines);
9496
const newLines = ActionUtils.constructNewContents(
95-
categories_map,
96-
color_schema_entry[0]
97+
categoriesMap,
98+
colorSchemaEntry[0],
99+
base64SchemaEntry[0]
97100
);
98101

99102
const finalLines = [

‎src/utils/constructNewContents.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,30 @@ const ColorMap: Record<TTextColor | 'green', string> = {
1717
};
1818

1919
export const constructNewContents = (
20-
categories_map: ICategoryMap,
21-
color_schema_unit_key: string
20+
categoriesMap: ICategoryMap,
21+
colorSchemaUnitKey: string,
22+
base64SchemaUnitKey: string
2223
) => {
2324
const newContents: string[] = [];
24-
for (const [category, category_info] of categories_map) {
25+
for (const [category, categoryInfo] of categoriesMap) {
2526
const content = [
2627
`<h3><img height="20px" src="https://img.shields.io/badge/${qs.escape(
2728
category
28-
)}-${ColorMap[category_info.color]}"/></h3>`
29+
)}-${ColorMap[categoryInfo.color]}"/></h3>`
2930
];
30-
category_info.items.forEach((item) => {
31+
categoryInfo.items.forEach((item) => {
3132
const title = item.title && item.title[0][0];
3233
if (!title)
3334
throw new Error(`Each row must have value in the Name column`);
35+
let logo: string = qs.escape(title);
36+
// At first check if the user provided a base64 encoded svg logo
37+
if (item[base64SchemaUnitKey]?.[0][0]) {
38+
logo = item[base64SchemaUnitKey][0][0];
39+
}
3440
content.push(
3541
`<span><img src="https://img.shields.io/badge/-${qs.escape(title)}-${
36-
item[color_schema_unit_key]?.[0][0] ?? 'black'
37-
}?style=flat-square&amp;logo=${qs.escape(
38-
title
39-
)}" alt="${title}"/></span>`
42+
item[colorSchemaUnitKey]?.[0][0] ?? 'black'
43+
}?style=flat-square&amp;logo=${logo}" alt="${title}"/></span>`
4044
);
4145
});
4246
newContents.push(...content, '<hr>');

‎src/utils/getSchemaEntries.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88

99
export const getSchemaEntries = (schema: Schema) => {
1010
const schemaEntries = Object.entries(schema);
11-
let categorySchemaEntry: [string, SelectSchemaUnit] | undefined =undefined,
12-
nameSchemaEntry: [string, TitleSchemaUnit] | undefined =undefined,
13-
colorSchemaEntry: [string, TextSchemaUnit] | undefined =undefined,
14-
base64SchemaEntry: [string, TextSchemaUnit] | undefined =undefined;
11+
let categorySchemaEntry: [string, SelectSchemaUnit] = undefined asany,
12+
nameSchemaEntry: [string, TitleSchemaUnit] = undefined asany,
13+
colorSchemaEntry: [string, TextSchemaUnit] = undefined asany,
14+
base64SchemaEntry: [string, TextSchemaUnit] = undefined asany;
1515

1616
schemaEntries.forEach((schemaEntry) => {
1717
if (schemaEntry[1].type === 'text' && schemaEntry[1].name === 'Color') {

‎src/utils/modifyRows.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { IPage, RecordMap } from '@nishans/types';
22

3+
/**
4+
* Sorts an array of page blocks by their title
5+
* @param recordMap Record map to sort blocks from
6+
* @param databaseId Database id to filter block
7+
* @returns An array of pages sorted by their title
8+
*/
39
export const modifyRows = (
410
recordMap: Pick<RecordMap, 'block'>,
511
databaseId: string

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /