Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list-json.js use moment format error #25

Open
anran758 opened this issue May 7, 2020 · 0 comments
Open

list-json.js use moment format error #25

anran758 opened this issue May 7, 2020 · 0 comments

Comments

@anran758
Copy link

anran758 commented May 7, 2020

I encountered some problems when using hexo-related-popular-posts:

05:41:55.845 ERROR Render HTML failed: 2020/02/22/flexbox-use-cases/index.html
TypeError: Cannot read property 'replace' of null
    at Hexo.externalLinkFilter (/Users/anran/project_my/blog/node_modules/hexo/lib/plugins/filter/after_render/external_link.js:22:15)
    at Hexo.tryCatcher (/Users/anran/project_my/blog/node_modules/bluebird/js/release/util.js:16:23)
    at Hexo.<anonymous> (/Users/anran/project_my/blog/node_modules/bluebird/js/release/method.js:15:34)
    at /Users/anran/project_my/blog/node_modules/hexo/lib/extend/filter.js:62:52
    at tryCatcher (/Users/anran/project_my/blog/node_modules/bluebird/js/release/util.js:16:23)
    at Object.gotValue (/Users/anran/project_my/blog/node_modules/bluebird/js/release/reduce.js:166:18)
    at Object.gotAccum (/Users/anran/project_my/blog/node_modules/bluebird/js/release/reduce.js:155:25)
    at Object.tryCatcher (/Users/anran/project_my/blog/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/anran/project_my/blog/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/anran/project_my/blog/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromiseCtx (/Users/anran/project_my/blog/node_modules/bluebird/js/release/promise.js:641:10)
    at _drainQueueStep (/Users/anran/project_my/blog/node_modules/bluebird/js/release/async.js:97:12)
    at _drainQueue (/Users/anran/project_my/blog/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/anran/project_my/blog/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/anran/project_my/blog/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

After debugging, I found that the error is in list-json.js. in the getElm function tried to add ret.date, But an error occurred during the assignment.

The test code and test log are as follows:

// /node_modules/hexo-related-popular-posts/lib/list-json.js

        if (inOptions.isDate && list.date != '') {
            console.log('\nlist.date', list.date)
            console.log('\nlist.date1', moment(moment()))
            console.log('\nlist.date2', moment(list.date))

            const formatDate = moment(list.date)
            console.log('\nformatDate', formatDate)

            // ret.date =  moment(list.date).format(config.date_format || 'YYYY-MM-DD')
        }
05:50:42.164 INFO  Hexo is running at http://localhost:9000 . Press Ctrl+C to stop.
05:50:42.240 DEBUG Database saved
05:54:18.184 DEBUG Rendering HTML post: 2020/02/22/flexbox-use-cases/index.html

getElm [Function: getElm] 5 


list.date {
  _isAMomentObject: true,
  _i: '2020-02-05T13:36:54.000Z',
  _isUTC: false,
  _pf: {
    empty: false,
    unusedTokens: [],
    unusedInput: [],
    overflow: -2,
    charsLeftOver: 0,
    nullInput: false,
    invalidEra: null,
    invalidMonth: null,
    invalidFormat: false,
    userInvalidated: false,
    iso: false,
    parsedDateParts: [],
    era: null,
    meridiem: null,
    rfc2822: false,
    weekdayMismatch: false
  },
  _locale: {
    _calendar: {
      sameDay: '[Today at] LT',
      nextDay: '[Tomorrow at] LT',
      nextWeek: 'dddd [at] LT',
      lastDay: '[Yesterday at] LT',
      lastWeek: '[Last] dddd [at] LT',
      sameElse: 'L'
    },
    _longDateFormat: {
      LTS: 'h:mm:ss A',
      LT: 'h:mm A',
      L: 'MM/DD/YYYY',
      LL: 'MMMM D, YYYY',
      LLL: 'MMMM D, YYYY h:mm A',
      LLLL: 'dddd, MMMM D, YYYY h:mm A'
    },
    _invalidDate: 'Invalid date',
    _dayOfMonthOrdinalParse: {},
    _relativeTime: {
      future: 'in %s',
      past: '%s ago',
      s: 'a few seconds',
      ss: '%d seconds',
      m: 'a minute',
      mm: '%d minutes',
      h: 'an hour',
      hh: '%d hours',
      d: 'a day',
      dd: '%d days',
      w: 'a week',
      ww: '%d weeks',
      M: 'a month',
      MM: '%d months',
      y: 'a year',
      yy: '%d years'
    },
    _months: [
      'January',   'February',
      'March',     'April',
      'May',       'June',
      'July',      'August',
      'September', 'October',
      'November',  'December'
    ],
    _monthsShort: [
      'Jan', 'Feb', 'Mar',
      'Apr', 'May', 'Jun',
      'Jul', 'Aug', 'Sep',
      'Oct', 'Nov', 'Dec'
    ],
    _week: { dow: 0, doy: 6 },
    _weekdays: [
      'Sunday',
      'Monday',
      'Tuesday',
      'Wednesday',
      'Thursday',
      'Friday',
      'Saturday'
    ],
    _weekdaysMin: [
      'Su', 'Mo',
      'Tu', 'We',
      'Th', 'Fr',
      'Sa'
    ],
    _weekdaysShort: [
      'Sun', 'Mon',
      'Tue', 'Wed',
      'Thu', 'Fri',
      'Sat'
    ],
    _meridiemParse: {},
    _eras: [ [Object], [Object] ],
    _abbr: 'en',
    _config: {
      calendar: [Object],
      longDateFormat: [Object],
      invalidDate: 'Invalid date',
      dayOfMonthOrdinalParse: {},
      relativeTime: [Object],
      months: [Array],
      monthsShort: [Array],
      week: [Object],
      weekdays: [Array],
      weekdaysMin: [Array],
      weekdaysShort: [Array],
      meridiemParse: {},
      eras: [Array],
      abbr: 'en'
    },
    _dayOfMonthOrdinalParseLenient: {}
  },
  _d: '2020-02-05T13:36:54.000Z',
  _isValid: true,
  _z: null
}

list.date1 Moment<2020-05-07T13:54:18+08:00>
05:54:18.571 ERROR Render HTML failed: 2020/02/22/flexbox-use-cases/index.html
TypeError: Cannot read property 'replace' of null
    at Hexo.externalLinkFilter (/Users/anran/project_my/blog/node_modules/hexo/lib/plugins/filter/after_render/external_link.js:22:15)
    at Hexo.tryCatcher (/Users/anran/project_my/blog/node_modules/bluebird/js/release/util.js:16:23)
    at Hexo.<anonymous> (/Users/anran/project_my/blog/node_modules/bluebird/js/release/method.js:15:34)
    at /Users/anran/project_my/blog/node_modules/hexo/lib/extend/filter.js:62:52
    at tryCatcher (/Users/anran/project_my/blog/node_modules/bluebird/js/release/util.js:16:23)
    at Object.gotValue (/Users/anran/project_my/blog/node_modules/bluebird/js/release/reduce.js:166:18)
    at Object.gotAccum (/Users/anran/project_my/blog/node_modules/bluebird/js/release/reduce.js:155:25)
    at Object.tryCatcher (/Users/anran/project_my/blog/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/anran/project_my/blog/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/anran/project_my/blog/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromiseCtx (/Users/anran/project_my/blog/node_modules/bluebird/js/release/promise.js:641:10)
    at _drainQueueStep (/Users/anran/project_my/blog/node_modules/bluebird/js/release/async.js:97:12)
    at _drainQueue (/Users/anran/project_my/blog/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/anran/project_my/blog/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/anran/project_my/blog/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

It can be found in the log: moment caused an error while initializing list.date, which caused the subsequent formatDate log to not be output.

If I delete the code about moment (list.date), hexo will work normally.

The current configuration of hexo is as follows:

hexo: 4.2.0
hexo-cli: 3.1.0
os: Darwin 17.7.0 darwin x64
node: 12.13.1
v8: 7.7.299.13-node.16
uv: 1.33.1
zlib: 1.2.11
brotli: 1.0.7
ares: 1.15.0
modules: 72
nghttp2: 1.39.2
napi: 5
llhttp: 1.1.4
http_parser: 2.8.0
openssl: 1.1.1d
cldr: 35.1
icu: 64.2
tz: 2019c
unicode: 12.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant