Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/marked-9.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
takurinton committed Mar 28, 2024
2 parents 2258957 + f4d7a3a commit be9e94e
Show file tree
Hide file tree
Showing 27 changed files with 401 additions and 1,169 deletions.
13 changes: 0 additions & 13 deletions .github/dependabot.yml

This file was deleted.

Binary file modified bun.lockb
Binary file not shown.
23 changes: 10 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,28 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "bun run prebuild && wmr",
"build": "tsc && NODE_ENV=production && bun run prebuild && wmr build --prerender && bun run make-feed",
"dev": "wmr",
"build": "NODE_ENV=production wmr build --prerender",
"serve": "wmr serve",
"lint": "eslint './**/*.{js,jsx,ts,tsx}'",
"gen": "bun run ./scripts/gen-template.js",
"prebuild": "bun run ./scripts/pre-build.js",
"make-feed": "bun run ./scripts/make-feed.js"
"lint": "eslint './{public,src}/**/*.{js,jsx,ts,tsx}'",
"gen": "bun run ./scripts/gen-template.js"
},
"alias": {
"react": "preact/compat"
},
"devDependencies": {
"@types/node": "18.11.9",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.59.2",
"eslint": "8.49.0",
"@typescript-eslint/eslint-plugin": "6.8.0",
"@typescript-eslint/parser": "6.8.0",
"eslint": "8.52.0",
"eslint-config-preact": "1.3.0",
"typescript": "5.1.3",
"typescript": "5.2.2",
"wmr": "3.8.0"
},
"dependencies": {
"hoofd": "1.7.0",
"marked": "9.1.2",
"preact": "10.17.1",
"preact-iso": "2.3.1"
"preact": "10.18.1",
"preact-iso": "2.5.0"
},
"author": "takurinton",
"eslintConfig": {
Expand Down
21 changes: 17 additions & 4 deletions scripts/make-feed.js → plugins/feed/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { writeFileSync, readFileSync, readdirSync } from "fs";
import { writeFileSync, readFileSync } from "fs";

(() => {
export default function feedPlugin({ plugins, cwd, prod }, opts) {
plugins.push(feed({ cwd, prod, ...opts }));
}

function feed() {
return {
name: "feed",
async load() {
makeFeed();
},
};
}

function makeFeed() {
const posts = JSON.parse(
readFileSync(`${process.cwd()}/public/contents/posts.json`)
);
Expand Down Expand Up @@ -29,7 +42,7 @@ import { writeFileSync, readFileSync, readdirSync } from "fs";
<title>${content.title} | たくりんとんのブログ</title>
<link>https://blog.takurinton.dev/post/${content.id}</link>
<pubDate>${new Date(content.created_at).toUTCString()}</pubDate>
<description>${content.content}</description>
<description>${content.description}</description>
<guid>https://blog.takurinton.dev/post/${content.id}</guid>
</item>`
)
Expand All @@ -41,4 +54,4 @@ import { writeFileSync, readFileSync, readdirSync } from "fs";
if (err) throw err;
console.log(`posts.json updated.`);
});
})();
}
22 changes: 18 additions & 4 deletions scripts/pre-build.js → plugins/sentence/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { writeFileSync, readFileSync, readdirSync } from "fs";
import { marked } from "marked";

const markdownToString = (markdown) => {
export default function sentensePlugin({ plugins, cwd, prod }, opts) {
plugins.push(sentense({ cwd, prod, ...opts }));
}

function sentense() {
return {
name: "feed",
enforce: "pre",
configResolved() {
makeListObject();
},
};
}

function markdownToString(markdown) {
const html = marked(markdown);
const notTag = html.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g, "");
const breakToSpace = notTag.replace(/(\r\n|\n|\r)/gm, " ");
const removeTwitter = breakToSpace.replace(/@twitter\[.*\]/g, "");
const removeOg = removeTwitter.replace(/@og\[.*\]/g, "");
return removeOg;
};
}

const FRONTMATTER = /---\n([\s\S]*?)\n---\n\n([\s\S]*)/;
const FRONTMATTER_LIST =
/id:([\s\S]*)\ntitle:([\s\S]*)\ndescription:([\s\S]*)\ncreated_at:([\s\S]*)/;

(() => {
function makeListObject() {
const files = readdirSync(`${process.cwd()}/public/contents`);
const posts = files.filter((file) => file.match(/\.md$/));
const contents = posts.map((post) => {
Expand Down Expand Up @@ -50,4 +64,4 @@ const FRONTMATTER_LIST =
console.log(`posts.json updated.`);
}
);
})();
}
Loading

0 comments on commit be9e94e

Please sign in to comment.