Skip to content

Commit

Permalink
another attemt
Browse files Browse the repository at this point in the history
  • Loading branch information
tommerty committed Jan 5, 2025
1 parent 2cdb3c9 commit c8b88db
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 30 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].3
uses: dorasto/[email protected].4
with:
username: ${{ env.DORAS_USERNAME }}
23 changes: 10 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28024,30 +28024,27 @@ const fs = __importStar(__nccwpck_require__(9896));
async function run() {
try {
const username = core.getInput("username") || process.env.DORAS_USERNAME;
if (!username) {
throw new Error("Username is required");
}
core.info(`Processing for username: ${username}`);
const response = await axios_1.default.get(`https://doras.to/api/user/${username}/blocks?allblocks=true&filter=type:link`);
const links = response.data;
core.info(`Received ${response.data.length} links from API`);
// Generate markdown
let markdown = "## 🔗 My Links\n\n";
markdown += '<div align="center">\n\n';
links.forEach((link) => {
response.data.forEach((link) => {
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>&nbsp;&nbsp;`;
core.info(`Added link: ${link.name}`);
}
});
markdown += "\n\n</div>";
// Read existing README
// Read and update 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.info(`Reading from ${readmePath}`);
const readmeContent = fs.readFileSync(readmePath, "utf8");
const updatedContent = readmeContent.replace(/<!-- DORAS-LINKS-START -->[\s\S]*<!-- DORAS-LINKS-END -->/, `<!-- DORAS-LINKS-START -->\n${markdown}\n<!-- DORAS-LINKS-END -->`);
fs.writeFileSync(readmePath, updatedContent);
core.info("README.md updated successfully");
core.setOutput("markdown", markdown);
}
catch (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 not shown.
Binary file not shown.
Binary file modified node_modules/@vercel/ncc/dist/ncc/loaders/ts-loader.js.cache
Binary file not shown.
25 changes: 10 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import axios from "axios";
import * as fs from "fs";

Expand All @@ -16,45 +15,41 @@ async function run() {
const username =
core.getInput("username") || process.env.DORAS_USERNAME;

if (!username) {
throw new Error("Username is required");
}
core.info(`Processing for username: ${username}`);

const response = await axios.get(
`https://doras.to/api/user/${username}/blocks?allblocks=true&filter=type:link`
);

const links = response.data;
core.info(`Received ${response.data.length} links from API`);

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

links.forEach((link: DorasLink) => {
response.data.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>&nbsp;&nbsp;`;
core.info(`Added link: ${link.name}`);
}
});

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

// Read existing README
// Read and update README
const readmePath = "README.md";
let readmeContent = fs.readFileSync(readmePath, "utf8");
core.info(`Reading from ${readmePath}`);

// Update content between markers
readmeContent = readmeContent.replace(
const readmeContent = fs.readFileSync(readmePath, "utf8");
const updatedContent = 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);
fs.writeFileSync(readmePath, updatedContent);
core.info("README.md updated successfully");

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

0 comments on commit c8b88db

Please sign in to comment.