Skip to content

Commit

Permalink
Merge pull request #181 from yamadashy/feature/eleventy-v3
Browse files Browse the repository at this point in the history
feat(11ty): Eleventy v3対応
  • Loading branch information
yamadashy authored Oct 6, 2024
2 parents dd3f81c + b1c40b6 commit 71209ae
Show file tree
Hide file tree
Showing 16 changed files with 942 additions and 783 deletions.
7 changes: 4 additions & 3 deletions eleventy.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path';
import url from 'node:url';
import type Eleventy from '@11ty/eleventy';
import EleventyFetch from '@11ty/eleventy-fetch';
import EleventyImage from '@11ty/eleventy-img';
import CleanCSS from 'clean-css';
Expand Down Expand Up @@ -136,7 +135,8 @@ const minifyCssFilter = (css: string) => {
return new CleanCSS({}).minify(css).styles;
};

const supportTypeScriptTemplate = (eleventyConfig: Eleventy.UserConfig) => {
// biome-ignore lint/suspicious/noExplicitAny: This is intentional
const supportTypeScriptTemplate = (eleventyConfig: any) => {
eleventyConfig.addTemplateFormats('ts');
eleventyConfig.addExtension('ts', {
outputFileExtension: 'js',
Expand All @@ -149,7 +149,8 @@ const supportTypeScriptTemplate = (eleventyConfig: Eleventy.UserConfig) => {
});
};

module.exports = (eleventyConfig: Eleventy.UserConfig) => {
// biome-ignore lint/suspicious/noExplicitAny: This is intentional
module.exports = (eleventyConfig: any) => {
// static assets
eleventyConfig.addPassthroughCopy('src/site/images');
eleventyConfig.addPassthroughCopy('src/site/feeds');
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"main": "",
"scripts": {
"build": "yarn feed-generate && yarn site-build",
"feed-generate": "node --require esbuild-register src/feed/generate-feed-command.ts",
"register-index": "node --require esbuild-register src/feed/register-index-command.ts",
"site-build": "node --require esbuild-register ./node_modules/.bin/eleventy --config=eleventy.config.ts",
"site-serve": "node --require esbuild-register ./node_modules/.bin/eleventy --config=eleventy.config.ts --serve",
"feed-generate": "tsx src/feed/generate-feed-command.ts",
"register-index": "tsx src/feed/register-index-command.ts",
"site-build": "tsx ./node_modules/.bin/eleventy --config=eleventy.config.ts",
"site-serve": "tsx ./node_modules/.bin/eleventy --config=eleventy.config.ts --serve",
"lint": "biome check --write && tsc --noEmit && secretlint '**/*'",
"test": "vitest run",
"test-coverage": "vitest run --coverage",
Expand All @@ -21,13 +21,14 @@
"bugs": {
"url": "https://github.com/yamadashy/tech-blog-rss-feed/issues"
},
"type": "module",
"author": "yamadashy",
"license": "MIT",
"keywords": ["blog", "tech blog", "engineer blog", "engineering blog", "feed", "rss", "atom"],
"devDependencies": {
"@11ty/eleventy": "^2.0.1",
"@11ty/eleventy-fetch": "^4.0.0",
"@11ty/eleventy-img": "^4.0.2",
"@11ty/eleventy": "^3.0.0",
"@11ty/eleventy-fetch": "^4.0.1",
"@11ty/eleventy-img": "^5.0.0",
"@biomejs/biome": "^1.9.3",
"@secretlint/core": "^8.3.0",
"@secretlint/secretlint-rule-preset-recommend": "^8.3.0",
Expand All @@ -46,7 +47,6 @@
"axios": "^1.6.0",
"clean-css": "^5.3.3",
"dayjs": "^1.11.10",
"esbuild-register": "^3.5.0",
"fast-xml-parser": "^4.3.2",
"feed": "^4.2.2",
"googleapis": "^144.0.0",
Expand All @@ -60,6 +60,7 @@
"rss-parser": "^3.12.0",
"secretlint": "^8.3.0",
"sharp-ico": "^0.1.5",
"tsx": "^4.19.1",
"typescript": "^5.2.2",
"vitest": "^2.0.0"
},
Expand Down
3 changes: 1 addition & 2 deletions src/common/constants.js → src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @ts-check
const siteUrlStem = 'https://yamadashy.github.io/tech-blog-rss-feed';
const siteUrl = `${siteUrlStem}/`;

module.exports = {
export default {
// サイト設定
siteUrl: `${siteUrl}`,
siteUrlStem: siteUrlStem,
Expand Down
2 changes: 1 addition & 1 deletion src/common/eleventy-cache-option.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type EleventyImage from '@11ty/eleventy-img';
import constants from './constants';
import constants from './constants.js';

export const imageCacheOptions: EleventyImage.CacheOptions = {
duration: '3d',
Expand Down
7 changes: 5 additions & 2 deletions src/feed/generate-feed-command.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import * as path from 'node:path';
import * as url from 'node:url';
import { FEED_INFO_LIST } from '../resources/feed-info-list';
import { FeedCrawler } from './utils/feed-crawler';
import { FeedGenerator } from './utils/feed-generator';
import { ImagePrecacher as FeedImagePrecacher } from './utils/feed-image-precacher';
import { FeedStorer } from './utils/feed-storer';
import { FeedValidator } from './utils/feed-validator';

const dirName = url.fileURLToPath(new URL('.', import.meta.url));

const FEED_FETCH_CONCURRENCY = 50;
const FEED_OG_FETCH_CONCURRENCY = 20;
const FETCH_IMAGE_CONCURRENCY = 100;
const FILTER_ARTICLE_DATE = new Date(Date.now() - 14 * 24 * 60 * 60 * 1000);
const MAX_FEED_DESCRIPTION_LENGTH = 200;
const MAX_FEED_CONTENT_LENGTH = 500;
const STORE_FEEDS_DIR_PATH = path.join(__dirname, '../site/feeds');
const STORE_BLOG_FEEDS_DIR_PATH = path.join(__dirname, '../site/blog-feeds');
const STORE_FEEDS_DIR_PATH = path.join(dirName, '../site/feeds');
const STORE_BLOG_FEEDS_DIR_PATH = path.join(dirName, '../site/blog-feeds');

const feedCrawler = new FeedCrawler();
const feedGenerator = new FeedGenerator();
Expand Down
2 changes: 1 addition & 1 deletion src/feed/register-index-command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { google } from 'googleapis';
import * as request from 'request';
import * as constants from '../common/constants';
import constants from '../common/constants';
import { sleep } from './utils/common-util';
import type { BlogFeed } from './utils/feed-storer';
const key = require('../../storage/service_account.json');
Expand Down
2 changes: 1 addition & 1 deletion src/feed/utils/feed-generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Feed, type FeedOptions } from 'feed';
import * as constants from '../../common/constants';
import constants from '../../common/constants.js';
import { escapeTextForXml, textToMd5Hash, textTruncate } from './common-util';
import type { CustomRssParserItem, FeedItemHatenaCountMap, OgObjectMap } from './feed-crawler';
import { logger } from './logger';
Expand Down
2 changes: 1 addition & 1 deletion src/feed/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as log4js from 'log4js';
import log4js from 'log4js';

const logger = log4js.getLogger();

Expand Down
22 changes: 12 additions & 10 deletions src/site/_data/blogFeeds.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const path = require('node:path');
const fs = require('node:fs/promises');
const dayjs = require('dayjs');
require('dayjs/locale/ja');

dayjs.extend(require('dayjs/plugin/relativeTime'));
dayjs.extend(require('dayjs/plugin/timezone'));
dayjs.extend(require('dayjs/plugin/utc'));
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';
import 'dayjs/locale/ja';

dayjs.extend(relativeTime);
dayjs.extend(timezone);
dayjs.extend(utc);
dayjs.locale('ja');
dayjs.tz.setDefault('Asia/Tokyo');

module.exports = async () => {
let blogFeeds = JSON.parse(await fs.readFile(path.join(__dirname, '../blog-feeds/blog-feeds.json')));
export default async () => {
const blogFeedsModule = await import('../blog-feeds/blog-feeds.json');
let blogFeeds = blogFeedsModule.default;

// データ調整
for (const blogFeed of blogFeeds) {
Expand Down
4 changes: 2 additions & 2 deletions src/site/_data/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const constants = require('../../common/constants');
import constants from '../../common/constants.js';

module.exports = constants;
export default constants;
2 changes: 1 addition & 1 deletion src/site/_data/currentDate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = () => {
export default () => {
return new Date().toISOString();
};
22 changes: 12 additions & 10 deletions src/site/_data/feedItemsChunks.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const path = require('node:path');
const fs = require('node:fs/promises');
const dayjs = require('dayjs');
require('dayjs/locale/ja');

dayjs.extend(require('dayjs/plugin/relativeTime'));
dayjs.extend(require('dayjs/plugin/timezone'));
dayjs.extend(require('dayjs/plugin/utc'));
import dayjs from 'dayjs';
import 'dayjs/locale/ja';
import relativeTime from 'dayjs/plugin/relativeTime';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';

dayjs.extend(relativeTime);
dayjs.extend(timezone);
dayjs.extend(utc);
dayjs.locale('ja');
dayjs.tz.setDefault('Asia/Tokyo');

module.exports = async () => {
const feedData = JSON.parse(await fs.readFile(path.join(__dirname, '../feeds/feed.json')));
export default async () => {
const feedDataModule = await import('../feeds/feed.json');
const feedData = feedDataModule.default;

let feedItems = feedData.items;

Expand Down
22 changes: 12 additions & 10 deletions src/site/_data/feedItemsHot.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
const path = require('node:path');
const fs = require('node:fs/promises');
const dayjs = require('dayjs');
require('dayjs/locale/ja');

dayjs.extend(require('dayjs/plugin/relativeTime'));
dayjs.extend(require('dayjs/plugin/timezone'));
dayjs.extend(require('dayjs/plugin/utc'));
import dayjs from 'dayjs';
import 'dayjs/locale/ja';
import relativeTime from 'dayjs/plugin/relativeTime';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';

dayjs.extend(relativeTime);
dayjs.extend(timezone);
dayjs.extend(utc);
dayjs.locale('ja');
dayjs.tz.setDefault('Asia/Tokyo');

const FEED_ITEM_FILTER_DAY = 7;
const MIN_HATENA_BOOKMARK_AMOUNT = 3;

module.exports = async () => {
const feedData = JSON.parse(await fs.readFile(path.join(__dirname, '../feeds/feed.json')));
export default async () => {
const feedDataModule = await import('../feeds/feed.json');
const feedData = feedDataModule.default;

let feedItems = feedData.items;

Expand Down
8 changes: 3 additions & 5 deletions src/site/_data/lastModifiedBlogsDate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const fs = require('node:fs/promises');
const path = require('node:path');

module.exports = async () => {
const feedData = JSON.parse(await fs.readFile(path.join(__dirname, '../feeds/feed.json')));
export default async () => {
const feedDataModule = await import('../feeds/feed.json');
const feedData = feedDataModule.default;

return new Date(feedData.items[0].date_published).toISOString();
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"strict": true,
"target": "es2021",
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"lib": ["dom", "esnext"],
Expand Down
Loading

0 comments on commit 71209ae

Please sign in to comment.