Skip to content

Commit

Permalink
fix: update "date" on draft updates
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Oct 18, 2023
1 parent 2ea34ac commit 0f8c2bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/rss-to-twitter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ jobs:
with:
RSS_URL: "https://jser.info/rss/"
TWEET_TEMPLATE: '更新しました! "%title%" %url%'
UPDATE_WITHIN_MINUTES: 720 # post items that are published within 1/2day
TWITTER_APIKEY: ${{ secrets.TWITTER_APIKEY }}
UPDATE_WITHIN_MINUTES: 60 # 60min
TWITTER_APIKEY_SECRET: ${{ secrets.TWITTER_APIKEY_SECRET }}
TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
17 changes: 16 additions & 1 deletion actions/update-draft-pr/src/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ const renamePattern = (originalFilePath: string, content: string) => {
});
};

function updateContentDate(newContent: string) {
const datePattern = /^date\s?:\s(\d{4}-\d{2}-\d{2}.*)$/;
if (!datePattern.test(newContent)) {
return newContent;
}
return newContent.replace(datePattern, (_all, _) => {
const now = new Date();
return `date: ${now.toISOString()}`;
});
}

export const rename = async (payload: {
owner: string;
repo: string;
Expand Down Expand Up @@ -216,11 +227,15 @@ export const rename = async (payload: {
const newContent = newTitle
? replaceContentTitle(content, newTitle)
: content;
const updatedContentDate = updateContentDate(newContent);
return {
newFileName: newTitle
? renameFilePathWithNewTitle(fileName, newTitle)
: renamePattern(fileName, content),
newContent: embedHeadline({ content: newContent, headline: payload.headline })
newContent: embedHeadline({
content: updatedContentDate,
headline: payload.headline
})
};
}
});
Expand Down

0 comments on commit 0f8c2bd

Please sign in to comment.