Skip to content

Commit

Permalink
03
Browse files Browse the repository at this point in the history
  • Loading branch information
tommerty committed Jan 5, 2025
1 parent 044585b commit 2cdb3c9
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
- uses: actions/checkout@v4

- name: Generate Doras Links
uses: dorasto/[email protected].2
uses: dorasto/[email protected].3
with:
username: ${{ env.DORAS_USERNAME }}
15 changes: 10 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28020,6 +28020,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(7484));
const axios_1 = __importDefault(__nccwpck_require__(7269));
const fs = __importStar(__nccwpck_require__(9896));
async function run() {
try {
const username = core.getInput("username") || process.env.DORAS_USERNAME;
Expand All @@ -28035,15 +28036,19 @@ async function run() {
if (link.show) {
const iconName = link.icon.split("/").pop()?.replace(".svg", "") || "";
markdown += `<a href="${link.url}" target="_blank">`;
markdown += `<img src="${link.icon}" width="32" height="32" alt="${link.name}" title="${link.name}" /></a>  `;
markdown += `<img src="${link.icon}" width="32" height="32" alt="${link.name}" title="${link.name}" /></a>&nbsp;&nbsp;`;
}
});
markdown += "\n\n</div>";
// Write to DORAS_LINKS environment variable
// Read existing README
const readmePath = "README.md";
let readmeContent = fs.readFileSync(readmePath, "utf8");
// Update content between markers
readmeContent = readmeContent.replace(/<!-- DORAS-LINKS-START -->[\s\S]*<!-- DORAS-LINKS-END -->/, `<!-- DORAS-LINKS-START -->\n${markdown}\n<!-- DORAS-LINKS-END -->`);
// Write updated README
fs.writeFileSync(readmePath, readmeContent);
// Set output
core.setOutput("markdown", markdown);
// Optional: Write directly to a file
const fs = __nccwpck_require__(9896);
fs.writeFileSync("doras-links.md", markdown);
}
catch (error) {
if (error instanceof Error) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Binary file modified node_modules/@vercel/ncc/dist/ncc/cli.js.cache
Binary file not shown.
Binary file modified node_modules/@vercel/ncc/dist/ncc/index.js.cache
Binary file not shown.
Binary file modified node_modules/@vercel/ncc/dist/ncc/loaders/relocate-loader.js.cache
Binary file not shown.
Binary file not shown.
Binary file modified node_modules/@vercel/ncc/dist/ncc/loaders/ts-loader.js.cache
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doras-action",
"version": "1.0.2",
"version": "1.0.3",
"main": "src/index.ts",
"scripts": {
"build": "tsc",
Expand Down
27 changes: 19 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import axios from "axios";
import * as fs from "fs";

interface DorasLink {
url: string;
Expand All @@ -22,29 +24,38 @@ async function run() {
`https://doras.to/api/user/${username}/blocks?allblocks=true&filter=type:link`
);

const links: DorasLink[] = response.data;
const links = response.data;

// Generate markdown
let markdown = "## 🔗 My Links\n\n";
markdown += '<div align="center">\n\n';

links.forEach((link) => {
links.forEach((link: DorasLink) => {
if (link.show) {
const iconName =
link.icon.split("/").pop()?.replace(".svg", "") || "";
markdown += `<a href="${link.url}" target="_blank">`;
markdown += `<img src="${link.icon}" width="32" height="32" alt="${link.name}" title="${link.name}" /></a>  `;
markdown += `<img src="${link.icon}" width="32" height="32" alt="${link.name}" title="${link.name}" /></a>&nbsp;&nbsp;`;
}
});

markdown += "\n\n</div>";

// Write to DORAS_LINKS environment variable
core.setOutput("markdown", markdown);
// Read existing README
const readmePath = "README.md";
let readmeContent = fs.readFileSync(readmePath, "utf8");

// Update content between markers
readmeContent = readmeContent.replace(
/<!-- DORAS-LINKS-START -->[\s\S]*<!-- DORAS-LINKS-END -->/,
`<!-- DORAS-LINKS-START -->\n${markdown}\n<!-- DORAS-LINKS-END -->`
);

// Optional: Write directly to a file
const fs = require("fs");
fs.writeFileSync("doras-links.md", markdown);
// Write updated README
fs.writeFileSync(readmePath, readmeContent);

// Set output
core.setOutput("markdown", markdown);
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
Expand Down

0 comments on commit 2cdb3c9

Please sign in to comment.