Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into v7.0.0_9
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee committed Jan 11, 2024
2 parents a2432d6 + 15dc6ca commit dfa7d92
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 20 deletions.
41 changes: 33 additions & 8 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ name: Benchmark
on:
push:
paths:
- 'lib/**'
- "lib/**"
pull_request:
branches:
- master
paths-ignore:
- 'test/scripts/**'
- "test/scripts/**"

jobs:
benchmark:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node-version: ['14', '16', '18']
node-version: ["14", "16", "18"]
fail-fast: false
steps:
- uses: actions/checkout@v4
Expand All @@ -28,13 +28,16 @@ jobs:
run: npm install --silent
- name: Running benchmark
run: node test/benchmark.js --benchmark

profiling:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node-version: ['14', '16', '18']
node-version: ["14", "16", "18"]
fail-fast: false
env:
comment_file: ".tmp-comment-flamegraph-node${{ matrix.node-version }}.md"
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -52,8 +55,30 @@ jobs:
project: ./.tmp-hexo-theme-unit-test/0x/
login: ${{ secrets.SURGE_LOGIN }}
token: ${{ secrets.SURGE_TOKEN }}
- name: Comment PR
uses: marocchino/sticky-pull-request-comment@v2

- name: save comment to file
if: ${{github.event_name == 'pull_request' }}
run: |
echo "https://${{ github.sha }}-${{ matrix.node-version }}-hexo.surge.sh/flamegraph.html" > ${{env.comment_file}}
- uses: actions/upload-artifact@v4
if: ${{github.event_name == 'pull_request' }}
with:
retention-days: 1
name: comment-node${{ matrix.node-version }}
path: ${{env.comment_file}}

number:
runs-on: ubuntu-latest
if: ${{github.event_name == 'pull_request' }}
env:
pr_number_file: .tmp-comment-pr_number
steps:
- name: save PR number to file
run: |
echo -n "${{ github.event.number }}" > ${{env.pr_number_file}}
- uses: actions/upload-artifact@v4
with:
message: |
Publish flamegraph to https://${{ github.sha }}-${{ matrix.node-version }}-hexo.surge.sh/flamegraph.html
retention-days: 1
name: comment-pr_number
path: ${{env.pr_number_file}}
51 changes: 47 additions & 4 deletions .github/workflows/commenter.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
name: Commenter

on: [pull_request_target]
on:
pull_request_target:

workflow_run:
workflows: ["Benchmark"]
types:
- completed

permissions:
contents: read

jobs:
commenter:
comment-test:
permissions:
pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment
pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment
runs-on: ubuntu-latest
if: ${{github.event_name == 'pull_request_target' }}
steps:
- name: Comment PR
- name: Comment PR - How to test
uses: marocchino/sticky-pull-request-comment@v2
with:
header: How to test
message: |
## How to test
Expand All @@ -23,3 +31,38 @@ jobs:
npm install
npm test
```
comment-flamegraph:
permissions:
pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment
actions: read # get artifact
runs-on: ubuntu-latest
if: ${{github.event_name == 'workflow_run' }}
env:
comment_result: ".tmp-comment-flamegraph.md"
steps:
- name: download artifact
uses: actions/download-artifact@v4
with:
github-token: ${{secrets.GITHUB_TOKEN}}
run-id: ${{toJSON(github.event.workflow_run.id)}}
pattern: "comment-*"
merge-multiple: true

- name: get PR number
run: |
echo "pr_number=$(cat .tmp-comment-pr_number)" >> "$GITHUB_ENV"
- name: combime comment
run: |
echo "## flamegraph" > ${{env.comment_result}}
echo "" >> ${{env.comment_result}}
cat .tmp-comment-flamegraph-*.md >> ${{env.comment_result}}
- name: Comment PR - flamegraph
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
number: ${{env.pr_number}}
header: flamegraph
path: ${{env.comment_result}}
82 changes: 82 additions & 0 deletions lib/hexo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,88 @@ declare module 'module' {
_cache: any;
}

interface Hexo {

/**
* Emitted before deployment begins.
* @param event
* @param listener
* @link https://hexo.io/api/events.html#deployBefore
*/
on(event: 'deployBefore', listener: (...args: any[]) => any): this;

/**
* Emitted after deployment begins.
* @param event
* @param listener
* @link https://hexo.io/api/events.html#deployAfter
*/
on(event: 'deployAfter', listener: (...args: any[]) => any): this;

/**
* Emitted before Hexo exits.
* @param event
* @param listener
* @link https://hexo.io/api/events.html#exit
*/
on(event: 'exit', listener: (...args: any[]) => any): this;

/**
* Emitted before generation begins.
* @param event
* @param listener
* @link https://hexo.io/api/events.html#generateBefore
*/
on(event: 'generateBefore', listener: (...args: any[]) => any): this;

/**
* Emitted after generation finishes.
* @param event
* @param listener
* @link https://hexo.io/api/events.html#generateAfter
*/
on(event: 'generateAfter', listener: (...args: any[]) => any): this;

/**
* Emitted after a new post has been created. This event returns the post data:
* @param event
* @param listener
* @link https://hexo.io/api/events.html#new
*/
on(event: 'new', listener: (post: { path: string; content: string; }) => any): this;

/**
* Emitted before processing begins. This event returns a path representing the root directory of the box.
* @param event
* @param listener
* @link https://hexo.io/api/events.html#processBefore
*/
on(event: 'processBefore', listener: (...args: any[]) => any): this;

/**
* Emitted after processing finishes. This event returns a path representing the root directory of the box.
* @param event
* @param listener
* @link https://hexo.io/api/events.html#processAfter
*/
on(event: 'processAfter', listener: (...args: any[]) => any): this;

/**
* Emitted after initialization finishes.
* @param event
* @param listener
*/
on(event: 'ready', listener: (...args: any[]) => any): this;

/**
* undescripted on emit
* @param event
* @param listener
*/
on(event: string, listener: (...args: any[]) => any): any;
emit(event: string, ...args: any[]): any;
}

class Hexo extends EventEmitter {
public base_dir: string;
public public_dir: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/hexo/multi_config_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export = (ctx: Hexo) => function multiConfigPath(base: string, configPaths: stri
return defaultPath;
}

log.i('Config based on', count, 'files');
log.i('Config based on', count.toString(), 'files');

const multiconfigRoot = outputDir || base;
const outputPath = join(multiconfigRoot, '_multiconfig.yml');
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/console/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class Generater {
const interval = prettyHrtime(process.hrtime(this.start));
const count = result.filter(Boolean).length;

log.info('%d files generated in %s', count, cyan(interval));
log.info('%d files generated in %s', count.toString(), cyan(interval));
});
}
execWatch(): Promise<void> {
Expand Down
13 changes: 11 additions & 2 deletions lib/plugins/tag/post_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ import type Hexo from '../../hexo';
*/
export = (ctx: Hexo) => {
return function postLinkTag(args: string[]) {
const slug = args.shift();
let slug = args.shift();
if (!slug) {
throw new Error(`Post not found: "${slug}" doesn't exist for {% post_link %}`);
}

let hash = '';
const parts = slug.split('#');

if (parts.length === 2) {
slug = parts[0];
hash = parts[1];
}

let escape = args[args.length - 1];
if (escape === 'true' || escape === 'false') {
args.pop();
Expand All @@ -33,7 +41,8 @@ export = (ctx: Hexo) => {
const attrTitle = escapeHTML(post.title || post.slug);
if (escape === 'true') title = escapeHTML(title);

const link = encodeURL(new URL(post.path, ctx.config.url).pathname);
const url = new URL(post.path, ctx.config.url).pathname + (hash ? `#${hash}` : '');
const link = encodeURL(url);

return `<a href="${link}" title="${attrTitle}">${title}</a>`;
};
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@
"@types/node": "^18.11.8",
"@types/nunjucks": "^3.2.2",
"@types/text-table": "^0.2.4",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"0x": "^5.1.2",
"c8": "^8.0.0",
"c8": "^9.0.0",
"chai": "^4.3.6",
"cheerio": "0.22.0",
"decache": "^4.6.1",
Expand All @@ -87,7 +85,7 @@
"mocha": "^10.0.0",
"sinon": "^15.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
"typescript": "^5.3.2"
},
"engines": {
"node": ">=14"
Expand Down
4 changes: 4 additions & 0 deletions test/scripts/tags/post_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ describe('post_link', () => {
it('should throw if post not found', () => {
should.throw(() => postLink(['bar']), Error, /Post not found: post_link bar\./);
});

it('should keep hash', () => {
postLink(['foo#bar']).should.eql('<a href="/foo/#bar" title="Hello world">Hello world</a>');
});
});

0 comments on commit dfa7d92

Please sign in to comment.