Skip to content

Commit 2cdb3c9

Browse files
committed
03
1 parent 044585b commit 2cdb3c9

File tree

10 files changed

+32
-16
lines changed

10 files changed

+32
-16
lines changed

.github/workflows/example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ jobs:
1515
- uses: actions/checkout@v4
1616

1717
- name: Generate Doras Links
18-
uses: dorasto/github-links@v1.0.2
18+
uses: dorasto/github-links@v1.0.3
1919
with:
2020
username: ${{ env.DORAS_USERNAME }}

dist/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28020,6 +28020,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
2802028020
Object.defineProperty(exports, "__esModule", ({ value: true }));
2802128021
const core = __importStar(__nccwpck_require__(7484));
2802228022
const axios_1 = __importDefault(__nccwpck_require__(7269));
28023+
const fs = __importStar(__nccwpck_require__(9896));
2802328024
async function run() {
2802428025
try {
2802528026
const username = core.getInput("username") || process.env.DORAS_USERNAME;
@@ -28035,15 +28036,19 @@ async function run() {
2803528036
if (link.show) {
2803628037
const iconName = link.icon.split("/").pop()?.replace(".svg", "") || "";
2803728038
markdown += `<a href="${link.url}" target="_blank">`;
28038-
markdown += `<img src="${link.icon}" width="32" height="32" alt="${link.name}" title="${link.name}" /></a>  `;
28039+
markdown += `<img src="${link.icon}" width="32" height="32" alt="${link.name}" title="${link.name}" /></a>&nbsp;&nbsp;`;
2803928040
}
2804028041
});
2804128042
markdown += "\n\n</div>";
28042-
// Write to DORAS_LINKS environment variable
28043+
// Read existing README
28044+
const readmePath = "README.md";
28045+
let readmeContent = fs.readFileSync(readmePath, "utf8");
28046+
// Update content between markers
28047+
readmeContent = readmeContent.replace(/<!-- DORAS-LINKS-START -->[\s\S]*<!-- DORAS-LINKS-END -->/, `<!-- DORAS-LINKS-START -->\n${markdown}\n<!-- DORAS-LINKS-END -->`);
28048+
// Write updated README
28049+
fs.writeFileSync(readmePath, readmeContent);
28050+
// Set output
2804328051
core.setOutput("markdown", markdown);
28044-
// Optional: Write directly to a file
28045-
const fs = __nccwpck_require__(9896);
28046-
fs.writeFileSync("doras-links.md", markdown);
2804728052
}
2804828053
catch (error) {
2804928054
if (error instanceof Error) {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 Bytes
Binary file not shown.
53.9 KB
Binary file not shown.
32 Bytes
Binary file not shown.
Binary file not shown.
152 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "doras-action",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"main": "src/index.ts",
55
"scripts": {
66
"build": "tsc",

src/index.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as core from "@actions/core";
2+
import * as exec from "@actions/exec";
23
import axios from "axios";
4+
import * as fs from "fs";
35

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

25-
const links: DorasLink[] = response.data;
27+
const links = response.data;
2628

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

31-
links.forEach((link) => {
33+
links.forEach((link: DorasLink) => {
3234
if (link.show) {
3335
const iconName =
3436
link.icon.split("/").pop()?.replace(".svg", "") || "";
3537
markdown += `<a href="${link.url}" target="_blank">`;
36-
markdown += `<img src="${link.icon}" width="32" height="32" alt="${link.name}" title="${link.name}" /></a>  `;
38+
markdown += `<img src="${link.icon}" width="32" height="32" alt="${link.name}" title="${link.name}" /></a>&nbsp;&nbsp;`;
3739
}
3840
});
3941

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

42-
// Write to DORAS_LINKS environment variable
43-
core.setOutput("markdown", markdown);
44+
// Read existing README
45+
const readmePath = "README.md";
46+
let readmeContent = fs.readFileSync(readmePath, "utf8");
47+
48+
// Update content between markers
49+
readmeContent = readmeContent.replace(
50+
/<!-- DORAS-LINKS-START -->[\s\S]*<!-- DORAS-LINKS-END -->/,
51+
`<!-- DORAS-LINKS-START -->\n${markdown}\n<!-- DORAS-LINKS-END -->`
52+
);
4453

45-
// Optional: Write directly to a file
46-
const fs = require("fs");
47-
fs.writeFileSync("doras-links.md", markdown);
54+
// Write updated README
55+
fs.writeFileSync(readmePath, readmeContent);
56+
57+
// Set output
58+
core.setOutput("markdown", markdown);
4859
} catch (error) {
4960
if (error instanceof Error) {
5061
core.setFailed(error.message);

0 commit comments

Comments
 (0)