mirror of
https://github.com/gapmiss/badges.git
synced 2026-07-22 04:41:25 +00:00
Fix ESLint and Obsidian scorecard issues
- Add eslint-plugin-obsidianmd with typescript-eslint type-checked rules - Fix TypeScript: remove any types, unused vars, console.log statements - Fix DOM: use createSpan() instead of document.createElement - Fix CSS: remove !important declarations - Replace builtin-modules with Node's module.builtinModules - Pin @codemirror dependencies to exact versions - Add pnpm lockfile for reproducible builds - Add GitHub workflow for artifact attestation - Add release script Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
58e5d8e5c6
commit
a9f96d55b5
14 changed files with 3509 additions and 94 deletions
|
|
@ -1,3 +0,0 @@
|
|||
node_modules/
|
||||
|
||||
main.js
|
||||
23
.eslintrc
23
.eslintrc
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"env": { "node": true },
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"no-prototype-builtins": "off",
|
||||
"@typescript-eslint/no-empty-function": "off"
|
||||
}
|
||||
}
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -22,4 +22,4 @@ data.json
|
|||
.DS_Store
|
||||
|
||||
.hotreload
|
||||
package-lock.json
|
||||
.claude
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import esbuild from "esbuild";
|
||||
import process from "process";
|
||||
import builtins from "builtin-modules";
|
||||
import { builtinModules } from "module";
|
||||
|
||||
const banner =
|
||||
`/*
|
||||
|
|
@ -31,7 +31,7 @@ const context = await esbuild.context({
|
|||
"@lezer/common",
|
||||
"@lezer/highlight",
|
||||
"@lezer/lr",
|
||||
...builtins],
|
||||
...builtinModules],
|
||||
format: "cjs",
|
||||
target: "es2018",
|
||||
logLevel: "info",
|
||||
|
|
|
|||
29
eslint.config.mjs
Normal file
29
eslint.config.mjs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import tsParser from "@typescript-eslint/parser";
|
||||
import tseslint from "typescript-eslint";
|
||||
import obsidianmd from "eslint-plugin-obsidianmd";
|
||||
|
||||
export default [
|
||||
{ ignores: ["node_modules/**", "main.js", "*.mjs", "package.json", "package-lock.json", "versions.json", "tsconfig.json"] },
|
||||
...tseslint.configs.recommendedTypeChecked.map(config => ({
|
||||
...config,
|
||||
files: ["src/**/*.ts"],
|
||||
})),
|
||||
...obsidianmd.configs.recommended,
|
||||
{
|
||||
files: ["src/**/*.ts"],
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
parserOptions: {
|
||||
project: "./tsconfig.json",
|
||||
sourceType: "module",
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
"no-console": ["error", { allow: ["warn", "error", "debug"] }],
|
||||
"@typescript-eslint/no-unused-vars": ["error", {
|
||||
argsIgnorePattern: "^_",
|
||||
varsIgnorePattern: "^_",
|
||||
}],
|
||||
},
|
||||
},
|
||||
];
|
||||
12
package.json
12
package.json
|
|
@ -13,15 +13,17 @@
|
|||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.6",
|
||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||
"@typescript-eslint/parser": "5.29.0",
|
||||
"builtin-modules": "3.3.0",
|
||||
"@typescript-eslint/parser": "^8.59.4",
|
||||
"esbuild": "0.17.3",
|
||||
"eslint": "^9.39.4",
|
||||
"eslint-plugin-obsidianmd": "^0.3.0",
|
||||
"obsidian": "latest",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.4"
|
||||
"typescript": "5.4.5",
|
||||
"typescript-eslint": "^8.59.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@codemirror/state": "^6.3.2"
|
||||
"@codemirror/state": "6.5.0",
|
||||
"@codemirror/view": "6.38.6"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3049
pnpm-lock.yaml
Normal file
3049
pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load diff
2
pnpm-workspace.yaml
Normal file
2
pnpm-workspace.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
allowBuilds:
|
||||
esbuild: set this to true or false
|
||||
332
release.mjs
Normal file
332
release.mjs
Normal file
|
|
@ -0,0 +1,332 @@
|
|||
import { readFileSync, writeFileSync } from 'fs';
|
||||
import { execSync } from 'child_process';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* Version Update and Deployment Automation Script
|
||||
*
|
||||
* 1. Update version in package.json
|
||||
* 2. Synchronize version in manifest.json, versions.json
|
||||
* 3. Run build
|
||||
* 4. Create Git commit
|
||||
* 5. Create Git tag
|
||||
* 6. Push changes to GitHub (REQUIRES Github CLI: https://cli.github.com)
|
||||
*/
|
||||
|
||||
// Version type definitions
|
||||
const VERSION_TYPES = {
|
||||
PATCH: 'patch',
|
||||
MINOR: 'minor',
|
||||
MAJOR: 'major'
|
||||
};
|
||||
|
||||
// Default settings
|
||||
const DEFAULT_VERSION_TYPE = VERSION_TYPES.PATCH;
|
||||
const RELEASE_FILES = ['main.js', 'manifest.json', 'styles.css'];
|
||||
const MIN_APP_VERSION = "0.15.0"
|
||||
|
||||
// Store original versions for rollback if needed
|
||||
let originalPackageVersion = '';
|
||||
let originalManifestVersion = '';
|
||||
|
||||
/**
|
||||
* Updates version value from the version string.
|
||||
* @param {string} version - Current version (e.g., '0.2.2')
|
||||
* @param {string} type - Update type ('patch', 'minor', 'major')
|
||||
* @returns {string} Updated version
|
||||
*/
|
||||
const updateVersion = (version, type = DEFAULT_VERSION_TYPE) => {
|
||||
const [major, minor, patch] = version.split('.').map(Number);
|
||||
|
||||
switch (type) {
|
||||
case VERSION_TYPES.MAJOR:
|
||||
return `${major + 1}.0.0`;
|
||||
case VERSION_TYPES.MINOR:
|
||||
return `${major}.${minor + 1}.0`;
|
||||
case VERSION_TYPES.PATCH:
|
||||
default:
|
||||
return `${major}.${minor}.${patch + 1}`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets version information before any changes are made.
|
||||
* @returns {string} Previous version
|
||||
*/
|
||||
const getPreviousVersion = () => {
|
||||
const manifestPath = path.resolve(process.cwd(), 'manifest.json');
|
||||
const manifestData = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
||||
return manifestData.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates version information in package.json file.
|
||||
* @param {string} versionType - Version type to update
|
||||
* @returns {string} New version
|
||||
*/
|
||||
const updatePackageVersion = (versionType) => {
|
||||
const packagePath = path.resolve(process.cwd(), 'package.json');
|
||||
const packageData = JSON.parse(readFileSync(packagePath, 'utf8'));
|
||||
|
||||
const currentVersion = packageData.version;
|
||||
originalPackageVersion = currentVersion; // Store original version for possible rollback
|
||||
const newVersion = updateVersion(currentVersion, versionType);
|
||||
|
||||
packageData.version = newVersion;
|
||||
writeFileSync(packagePath, JSON.stringify(packageData, null, '\t') + '\n');
|
||||
|
||||
console.log(`📦 Updated package.json version: ${currentVersion} → ${newVersion}`);
|
||||
return newVersion;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates version information in manifest.json file.
|
||||
* @param {string} newVersion - Version to update
|
||||
*/
|
||||
const updateManifestVersion = (newVersion) => {
|
||||
const manifestPath = path.resolve(process.cwd(), 'manifest.json');
|
||||
const manifestData = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
||||
|
||||
const currentVersion = manifestData.version;
|
||||
originalManifestVersion = currentVersion; // Store original version for possible rollback
|
||||
manifestData.version = newVersion;
|
||||
|
||||
writeFileSync(manifestPath, JSON.stringify(manifestData, null, '\t') + '\n');
|
||||
console.log(`📋 Updated manifest.json version: ${currentVersion} → ${newVersion}`);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates version information in versions.json file.
|
||||
* @param {string} previousVersion - Previous version
|
||||
* @param {string} newVersion - Version to update
|
||||
*/
|
||||
const updateVersionsVersion = (previousVersion, newVersion, minAppVersion) => {
|
||||
const versionsPath = path.resolve(process.cwd(), 'versions.json');
|
||||
const versionsData = JSON.parse(readFileSync(versionsPath, 'utf8'));
|
||||
|
||||
const manifestPath = path.resolve(process.cwd(), 'manifest.json');
|
||||
const manifestData = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
||||
|
||||
const currentVersion = manifestData.version;
|
||||
versionsData[newVersion] = minAppVersion;
|
||||
|
||||
writeFileSync(versionsPath, JSON.stringify(versionsData, null, '\t') + '\n');
|
||||
console.log(`📋 Updated versions.json version: ${previousVersion} → ${newVersion}`);
|
||||
};
|
||||
|
||||
/**
|
||||
* Run project build
|
||||
*/
|
||||
const buildProject = () => {
|
||||
try {
|
||||
console.log('🔨 Starting project build...');
|
||||
execSync('npm run build', { stdio: 'inherit' });
|
||||
console.log('✅ Build completed');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('❌ Build failed:', error.message);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Rollback version changes if the release process fails
|
||||
*/
|
||||
const rollbackVersions = () => {
|
||||
if (originalPackageVersion) {
|
||||
try {
|
||||
const packagePath = path.resolve(process.cwd(), 'package.json');
|
||||
const packageData = JSON.parse(readFileSync(packagePath, 'utf8'));
|
||||
const currentVersion = packageData.version;
|
||||
|
||||
packageData.version = originalPackageVersion;
|
||||
writeFileSync(packagePath, JSON.stringify(packageData, null, '\t') + '\n');
|
||||
console.log(`♻️ Rolled back package.json version: ${currentVersion} → ${originalPackageVersion}`);
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to rollback package.json version:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (originalManifestVersion) {
|
||||
try {
|
||||
const manifestPath = path.resolve(process.cwd(), 'manifest.json');
|
||||
const manifestData = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
||||
const currentVersion = manifestData.version;
|
||||
|
||||
const versionsPath = path.resolve(process.cwd(), 'versions.json');
|
||||
const versionsData = JSON.parse(readFileSync(versionsPath, 'utf8'));
|
||||
|
||||
// remove last version from JSON
|
||||
let keys = Object.keys(versionsData)
|
||||
delete versionsData[keys[keys.length-1]]
|
||||
|
||||
writeFileSync(versionsPath, JSON.stringify(versionsData, null, '\t') + '\n');
|
||||
console.log(`♻️ Rolled back versions.json version: ${currentVersion} → ${originalManifestVersion}`);
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to rollback versions.json version:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (originalManifestVersion) {
|
||||
try {
|
||||
const manifestPath = path.resolve(process.cwd(), 'manifest.json');
|
||||
const manifestData = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
||||
const currentVersion = manifestData.version;
|
||||
|
||||
manifestData.version = originalManifestVersion;
|
||||
writeFileSync(manifestPath, JSON.stringify(manifestData, null, '\t') + '\n');
|
||||
console.log(`♻️ Rolled back manifest.json version: ${currentVersion} → ${originalManifestVersion}`);
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to rollback manifest.json version:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Create Git commit and tag
|
||||
* @param {string} version - New version
|
||||
*/
|
||||
const createGitCommitAndTag = (version) => {
|
||||
try {
|
||||
// Stage changed files
|
||||
try {
|
||||
execSync('git add package.json manifest.json versions.json', { stdio: 'inherit' });
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to stage package.json, versions.json and manifest.json:', error.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try to stage release files
|
||||
try {
|
||||
execSync(`git add ${RELEASE_FILES.join(' ')}`, { stdio: 'inherit' });
|
||||
} catch (error) {
|
||||
console.warn('⚠️ Note: Some release files could not be staged. This may be normal if they are gitignored.');
|
||||
}
|
||||
|
||||
// Create commit
|
||||
const commitMessage = `chore: release ${version}`;
|
||||
execSync(`git commit -m "${commitMessage}"`, { stdio: 'inherit' });
|
||||
console.log(`✅ Commit created: ${commitMessage}`);
|
||||
|
||||
// Create tag
|
||||
const tagName = `${version}`;
|
||||
execSync(`git tag -a ${tagName} -m "Release ${tagName}"`, { stdio: 'inherit' });
|
||||
console.log(`🏷️ Tag created: ${tagName}`);
|
||||
|
||||
// Push changes
|
||||
execSync('git push', { stdio: 'inherit' });
|
||||
execSync('git push --tags', { stdio: 'inherit' });
|
||||
console.log('🚀 Changes pushed to GitHub');
|
||||
console.log('📦 GitHub Actions will create the release with artifact attestations.');
|
||||
return true; // Successfully created commit, tag, and pushed
|
||||
} catch (error) {
|
||||
console.error('❌ Error during Git operations:', error.message);
|
||||
return false; // Failed to complete Git operations
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if Git working tree is clean
|
||||
* @returns {boolean} Whether the working tree is clean
|
||||
*/
|
||||
const isGitWorkingTreeClean = () => {
|
||||
try {
|
||||
// Check for uncommitted changes
|
||||
const output = execSync('git status --porcelain', { encoding: 'utf-8' });
|
||||
return output.trim() === '';
|
||||
} catch (error) {
|
||||
console.error('❌ Error checking Git status:', error.message);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
const main = () => {
|
||||
let success = true;
|
||||
let newVersion = '';
|
||||
|
||||
try {
|
||||
// Check for uncommitted changes
|
||||
if (!isGitWorkingTreeClean()) {
|
||||
console.error('❌ Cannot proceed with release: You have uncommitted changes.');
|
||||
console.log('Please commit or stash your changes before running the release script.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Check command line arguments
|
||||
const args = process.argv.slice(2);
|
||||
const versionType = args[0] || DEFAULT_VERSION_TYPE;
|
||||
|
||||
if (!Object.values(VERSION_TYPES).includes(versionType)) {
|
||||
console.error(`❌ Invalid version type: ${versionType}`);
|
||||
console.log(`Valid options: ${Object.values(VERSION_TYPES).join(', ')}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let previousVersion = getPreviousVersion()
|
||||
|
||||
// Step 1: Update package.json version
|
||||
try {
|
||||
newVersion = updatePackageVersion(versionType);
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to update package.json version:', error.message);
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Step 2: Update manifest.json version
|
||||
if (success) {
|
||||
try {
|
||||
updateManifestVersion(newVersion);
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to update manifest.json version:', error.message);
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2.5: Update versions.json version
|
||||
if (success) {
|
||||
try {
|
||||
updateVersionsVersion(previousVersion, newVersion, MIN_APP_VERSION);
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to update versions.json version:', error.message);
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Build the project
|
||||
if (success) {
|
||||
if (!buildProject()) {
|
||||
console.error('❌ Build process failed.');
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 4: Git operations
|
||||
if (success) {
|
||||
if (!createGitCommitAndTag(newVersion)) {
|
||||
console.error('❌ Git operations failed.');
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check overall success
|
||||
if (success) {
|
||||
console.log(`\n🎉 Release ${newVersion} completed successfully!`);
|
||||
} else {
|
||||
console.error('❌ Release process failed. Rolling back version changes...');
|
||||
rollbackVersions();
|
||||
process.exit(1);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Unexpected error during release process:', error.message);
|
||||
rollbackVersions();
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
// Run script
|
||||
main();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
export const BADGE_TYPES:any[] = [
|
||||
export const BADGE_TYPES: [string, string, string][] = [
|
||||
["note", 'Note', 'lucide-pencil'],
|
||||
["info", 'Info', 'lucide-info'],
|
||||
["todo", 'Todo', 'lucide-check-circle-2'],
|
||||
|
|
|
|||
79
src/main.ts
79
src/main.ts
|
|
@ -7,7 +7,7 @@ const REGEXP = /(`\[!!([^\]]*)\]`)/gm;
|
|||
const TAGS = 'code'
|
||||
|
||||
export default class BadgesPlugin extends Plugin {
|
||||
public postprocessor: MarkdownPostProcessor = (el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
|
||||
public postprocessor: MarkdownPostProcessor = (el: HTMLElement, _ctx: MarkdownPostProcessorContext) => {
|
||||
const blockToReplace = el.querySelectorAll(TAGS)
|
||||
if (blockToReplace.length === 0) return
|
||||
|
||||
|
|
@ -33,11 +33,9 @@ export default class BadgesPlugin extends Plugin {
|
|||
buildPostProcessor()
|
||||
);
|
||||
this.registerEditorExtension(viewPlugin)
|
||||
console.log('Badges plugin loaded')
|
||||
}
|
||||
|
||||
onunload() {
|
||||
console.log('Badges plugin loaded')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +60,7 @@ class BadgeWidget extends WidgetType {
|
|||
super()
|
||||
}
|
||||
|
||||
toDOM(view: EditorView): HTMLElement {
|
||||
toDOM(_view: EditorView): HTMLElement {
|
||||
let text:string = this.badge[0].substring(1).substring(this.badge[0].length-2,0);
|
||||
return buildBadge(text);
|
||||
}
|
||||
|
|
@ -101,10 +99,10 @@ const viewPlugin = ViewPlugin.fromClass(class {
|
|||
const startOfLine = line.from;
|
||||
const endOfLine = line.to;
|
||||
|
||||
let currentLine = false;
|
||||
let _currentLine = false;
|
||||
currentSelections.forEach((r) => {
|
||||
if (r.to >= startOfLine && r.from <= endOfLine) {
|
||||
currentLine = true;
|
||||
_currentLine = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
|
@ -133,68 +131,54 @@ const viewPlugin = ViewPlugin.fromClass(class {
|
|||
decorations: (v) => v.decorations,
|
||||
})
|
||||
|
||||
function buildBadge(text: string) {
|
||||
// HTML Elements
|
||||
let newEl:HTMLElement = document.createElement("span");
|
||||
let iconEl:HTMLElement = document.createElement("span");
|
||||
let titleEl:HTMLElement = document.createElement("span");
|
||||
let textEl:HTMLElement = document.createElement("span");
|
||||
let attrType:any = "";
|
||||
let part:string = text.substring(2);
|
||||
let content:string = part.substring(part.length-1,1).trim();
|
||||
// no content
|
||||
if (!content.length) {
|
||||
newEl.setText("Badges syntax error");
|
||||
return newEl;
|
||||
}
|
||||
let parts:any[] = content.split(':');
|
||||
// return if NO CONTENT
|
||||
function buildBadge(text: string): HTMLSpanElement {
|
||||
const newEl = createSpan();
|
||||
const iconEl = createSpan();
|
||||
const titleEl = createSpan();
|
||||
const textEl = createSpan();
|
||||
let attrType = "";
|
||||
const part = text.substring(2);
|
||||
const content = part.substring(part.length-1,1).trim();
|
||||
if (!content.length) {
|
||||
newEl.setText("Badges syntax error");
|
||||
return newEl;
|
||||
}
|
||||
const parts = content.split(':');
|
||||
if (parts.length < 2) {
|
||||
newEl.setText("❌ Badges syntax error");
|
||||
newEl.setAttr("style", "color:var(--text-error)")
|
||||
return newEl;
|
||||
}
|
||||
// type of badge
|
||||
let badgeType:string = parts[0].trim();
|
||||
// build and check for extras
|
||||
let extras:any[] = badgeType.split("|");
|
||||
let hasExtra:boolean = extras.length > 1;
|
||||
// title value for badge
|
||||
let badgeContent:string = parts[1].trim();
|
||||
// custom badge
|
||||
newEl.setText("❌ Badges syntax error");
|
||||
newEl.setAttr("style", "color:var(--text-error)")
|
||||
return newEl;
|
||||
}
|
||||
let badgeType = parts[0].trim();
|
||||
const extras = badgeType.split("|");
|
||||
const hasExtra = extras.length > 1;
|
||||
const badgeContent = parts[1].trim();
|
||||
if (extras.length == 3) {
|
||||
// icon
|
||||
iconEl.addClass("inline-badge-icon");
|
||||
attrType = 'customized';
|
||||
setIcon(iconEl, extras[1]);
|
||||
iconEl.setAttr("aria-label", extras[2]);
|
||||
// details
|
||||
let details:any[] = parts[1].split("|");
|
||||
// title
|
||||
let title:string = details[0].trim();
|
||||
const details = parts[1].split("|");
|
||||
const title = details[0].trim();
|
||||
titleEl.addClass("inline-badge-title-inner");
|
||||
titleEl.setText(title);
|
||||
newEl.addClass('inline-badge');
|
||||
newEl.setAttr("data-inline-badge", attrType.toLowerCase());
|
||||
// color
|
||||
let color:string = 'currentColor';
|
||||
let color = 'currentColor';
|
||||
if (details[1]) {
|
||||
color = details[1].trim();
|
||||
}
|
||||
newEl.setAttr("style", "--customize-badge-color: "+color+";");
|
||||
// render
|
||||
newEl.appendChild(iconEl);
|
||||
if (textEl.getText() != "") {
|
||||
newEl.appendChild(textEl);
|
||||
}
|
||||
newEl.appendChild(titleEl);
|
||||
// set attrType to custom "key"
|
||||
attrType = extras.join("|");
|
||||
} else {
|
||||
if (hasExtra) {
|
||||
// Github badges
|
||||
if (extras[1].startsWith('ghb>') || extras[1].startsWith('ghs>')) {
|
||||
let ghType:string = extras[1].split('>')[1].trim();
|
||||
const ghType = extras[1].split('>')[1].trim();
|
||||
setIcon(iconEl, "github");
|
||||
iconEl.addClass("inline-badge-icon");
|
||||
iconEl.setAttr("aria-label", "Github");
|
||||
|
|
@ -203,25 +187,22 @@ function buildBadge(text: string) {
|
|||
iconEl.appendChild(textEl);
|
||||
attrType = (extras[1].startsWith('ghb>')) ? 'github' : 'github-success';
|
||||
badgeType = (extras[1].startsWith('ghb>')) ? 'github' : 'github-success';
|
||||
// NO icon, text-only
|
||||
} else {
|
||||
iconEl.addClass("inline-badge-extra");
|
||||
iconEl.setText(badgeType.split("|")[1].trim());
|
||||
attrType = 'text';
|
||||
badgeType = 'text';
|
||||
}
|
||||
// non-Github
|
||||
} else {
|
||||
iconEl.addClass("inline-badge-icon");
|
||||
attrType = badgeType.trim();
|
||||
BADGE_TYPES.forEach((el) => {
|
||||
if (el.indexOf(badgeType.toLowerCase()) === 0 && el[2].length > 0) {
|
||||
if (el[0] === badgeType.toLowerCase() && el[2].length > 0) {
|
||||
setIcon(iconEl, el[2]);
|
||||
iconEl.setAttr("aria-label", badgeType.trim());
|
||||
}
|
||||
});
|
||||
}
|
||||
// render
|
||||
titleEl.addClass("inline-badge-title-inner");
|
||||
titleEl.setText(badgeContent);
|
||||
newEl.addClass('inline-badge');
|
||||
|
|
|
|||
15
styles.css
15
styles.css
|
|
@ -19,14 +19,13 @@ body {
|
|||
content: ':';
|
||||
}
|
||||
.inline-badge .gh-type {
|
||||
display: inline-block !important;
|
||||
display: inline-block;
|
||||
font-size: var(--inline-badge-font-size);
|
||||
padding-right: .5em;
|
||||
padding-top: .15em;
|
||||
/* color: var(--color-blue); */
|
||||
}
|
||||
.inline-badge .inline-badge-extra {
|
||||
display: inline-block !important;
|
||||
display: inline-block;
|
||||
font-size: var(--inline-badge-font-size);
|
||||
padding-inline: .5em;
|
||||
padding-top: .15em;
|
||||
|
|
@ -41,10 +40,10 @@ body {
|
|||
}
|
||||
.inline-badge .inline-badge-extra,
|
||||
.inline-badge .inline-badge-icon {
|
||||
display: inline-flex !important;
|
||||
display: inline-flex;
|
||||
}
|
||||
.inline-badge .inline-badge-title-inner {
|
||||
display: inline-block !important;
|
||||
display: inline-block;
|
||||
font-size: var(--inline-badge-font-size);
|
||||
font-weight: inherit;
|
||||
padding-right: 5px;
|
||||
|
|
@ -390,9 +389,8 @@ body {
|
|||
color: rgba(var(--badge-color), 1);
|
||||
background-color: rgba(var(--badge-color),.123);
|
||||
}
|
||||
/* Github */
|
||||
.inline-badge[data-inline-badge="github"] .gh-type {
|
||||
color: var(--color-blue-rgb) !important;
|
||||
color: rgb(var(--color-blue-rgb));
|
||||
}
|
||||
.inline-badge[data-inline-badge="github"] .inline-badge-title-inner {
|
||||
color:var(--text-normal);
|
||||
|
|
@ -402,9 +400,8 @@ body {
|
|||
color: rgba(var(--badge-color), 1);
|
||||
background-color: rgba(var(--badge-color),.123);
|
||||
}
|
||||
/* Github SUCCESS */
|
||||
.inline-badge[data-inline-badge^="github-success"] .gh-type {
|
||||
color: var(--color-green-rgb) !important;
|
||||
color: rgb(var(--color-green-rgb));
|
||||
}
|
||||
.inline-badge[data-inline-badge^="github-success"] .inline-badge-title-inner {
|
||||
color:var(--text-normal);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,6 @@
|
|||
]
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts"
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
49
workflows/release.yml
Normal file
49
workflows/release.yml
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*.*.*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
attestations: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Attest main.js
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: main.js
|
||||
|
||||
- name: Attest styles.css
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: styles.css
|
||||
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
main.js
|
||||
manifest.json
|
||||
styles.css
|
||||
generate_release_notes: true
|
||||
Loading…
Reference in a new issue