• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hexojs / hexo / 3686149857

pending completion
3686149857

push

github

Mimi
rename to syntax_highlighter

2312 of 2434 branches covered (94.99%)

10 of 10 new or added lines in 6 files covered. (100.0%)

8344 of 8451 relevant lines covered (98.73%)

55.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.12
/lib/plugins/processor/asset.js
1
'use strict';
1✔
2

1✔
3
const { timezone, toDate, isExcludedFile, isMatch } = require('./common');
1✔
4
const Promise = require('bluebird');
1✔
5
const { parse: yfm } = require('hexo-front-matter');
1✔
6
const { extname, relative } = require('path');
1✔
7
const { Pattern } = require('hexo-util');
1✔
8
const { magenta } = require('picocolors');
1✔
9

1✔
10
module.exports = ctx => {
1✔
11
  return {
68✔
12
    pattern: new Pattern(path => {
68✔
13
      if (isExcludedFile(path, ctx.config)) return;
32✔
14

25✔
15
      return {
25✔
16
        renderable: ctx.render.isRenderable(path) && !isMatch(path, ctx.config.skip_render)
32✔
17
      };
32✔
18
    }),
68✔
19

68✔
20
    process: function assetProcessor(file) {
68✔
21
      if (file.params.renderable) {
42✔
22
        return processPage(ctx, file);
16✔
23
      }
16✔
24

26✔
25
      return processAsset(ctx, file);
26✔
26
    }
42✔
27
  };
68✔
28
};
1✔
29

1✔
30
function processPage(ctx, file) {
16✔
31
  const Page = ctx.model('Page');
16✔
32
  const { path } = file;
16✔
33
  const doc = Page.findOne({source: path});
16✔
34
  const { config } = ctx;
16✔
35
  const { timezone: timezoneCfg } = config;
16✔
36
  const updated_option = config.updated_option;
16✔
37

16✔
38
  if (file.type === 'skip' && doc) {
16!
39
    return;
×
40
  }
×
41

16✔
42
  if (file.type === 'delete') {
16✔
43
    if (doc) {
1✔
44
      return doc.remove();
1✔
45
    }
1✔
46

×
47
    return;
×
48
  }
×
49

15✔
50
  return Promise.all([
15✔
51
    file.stat(),
15✔
52
    file.read()
15✔
53
  ]).spread((stats, content) => {
15✔
54
    const data = yfm(content);
15✔
55
    const output = ctx.render.getOutput(path);
15✔
56

15✔
57
    data.source = path;
15✔
58
    data.raw = content;
15✔
59

15✔
60
    data.date = toDate(data.date);
15✔
61

15✔
62
    if (data.date) {
15✔
63
      if (timezoneCfg) data.date = timezone(data.date, timezoneCfg);
4✔
64
    } else {
15✔
65
      data.date = stats.ctime;
11✔
66
    }
11✔
67

15✔
68
    data.updated = toDate(data.updated);
15✔
69

15✔
70
    if (data.updated) {
15✔
71
      if (timezoneCfg) data.updated = timezone(data.updated, timezoneCfg);
3✔
72
    } else if (updated_option === 'date') {
15✔
73
      data.updated = data.date;
1✔
74
    } else if (updated_option === 'empty') {
12✔
75
      data.updated = undefined;
1✔
76
    } else {
11✔
77
      data.updated = stats.mtime;
10✔
78
    }
10✔
79

15✔
80
    if (data.permalink) {
15✔
81
      data.path = data.permalink;
3✔
82
      data.permalink = undefined;
3✔
83

3✔
84
      if (data.path.endsWith('/')) {
3✔
85
        data.path += 'index';
1✔
86
      }
1✔
87

3✔
88
      if (!extname(data.path)) {
3✔
89
        data.path += `.${output}`;
2✔
90
      }
2✔
91
    } else {
15✔
92
      data.path = `${path.substring(0, path.length - extname(path).length)}.${output}`;
12✔
93
    }
12✔
94

15✔
95
    if (!data.layout && output !== 'html' && output !== 'htm') {
15✔
96
      data.layout = false;
2✔
97
    }
2✔
98

15✔
99
    if (doc) {
15✔
100
      if (file.type !== 'update') {
1!
101
        ctx.log.warn(`Trying to "create" ${magenta(file.path)}, but the file already exists!`);
×
102
      }
×
103
      return doc.replace(data);
1✔
104
    }
1✔
105

14✔
106
    return Page.insert(data);
14✔
107
  });
15✔
108
}
16✔
109

1✔
110
function processAsset(ctx, file) {
26✔
111
  const id = relative(ctx.base_dir, file.source).replace(/\\/g, '/');
26✔
112
  const Asset = ctx.model('Asset');
26✔
113
  const doc = Asset.findById(id);
26✔
114

26✔
115
  if (file.type === 'delete') {
26✔
116
    if (doc) {
5✔
117
      return doc.remove();
5✔
118
    }
5✔
119

×
120
    return;
×
121
  }
×
122

21✔
123
  return Asset.save({
21✔
124
    _id: id,
21✔
125
    path: file.path,
21✔
126
    modified: file.type !== 'skip',
21✔
127
    renderable: file.params.renderable
21✔
128
  });
21✔
129
}
26✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc