[
  {
    "path": ".gitignore",
    "content": ".tern-port\n# Logs\nlogs\n*.log\n\n# Runtime data\npids\n*.pid\n*.seed\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n\n# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (http://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directory\n# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git\nnode_modules\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2015 She Jinxin\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n"
  },
  {
    "path": "README.md",
    "content": "# hexo-asset-image\n\n\nGive asset image in hexo a absolutely path automatically\n\n# Usege\n\n```shell\nnpm install hexo-asset-image --save\n```\n\n# Example\n\n```shell\nMacGesture2-Publish\n├── apppicker.jpg\n├── logo.jpg\n└── rules.jpg\nMacGesture2-Publish.md\n```\n\nMake sure `post_asset_folder: true` in your `_config.yml`.\n\nJust use `![logo](logo.jpg)` to insert `logo.jpg`.\n\n# History\n\n2018-04-18: support hexo-abbrlink\n"
  },
  {
    "path": "index.js",
    "content": "'use strict';\nvar cheerio = require('cheerio');\n\n// http://stackoverflow.com/questions/14480345/how-to-get-the-nth-occurrence-in-a-string\nfunction getPosition(str, m, i) {\n  return str.split(m, i).join(m).length;\n}\n\nhexo.extend.filter.register('after_post_render', function(data){\n  var config = hexo.config;\n  if(config.post_asset_folder){\n    var link = data.permalink;\n    var beginPos = getPosition(link, '/', 3) + 1;\n    var appendLink = '';\n    // In hexo 3.1.1, the permalink of \"about\" page is like \".../about/index.html\".\n    // if not with index.html endpos = link.lastIndexOf('.') + 1 support hexo-abbrlink\n    if(/.*\\/index\\.html$/.test(link)) {\n      // when permalink is end with index.html, for example 2019/02/20/xxtitle/index.html\n      // image in xxtitle/ will go to xxtitle/index/\n      appendLink = 'index/';\n      var endPos = link.lastIndexOf('/');\n    }\n    else {\n      var endPos = link.length-1;\n    }\n    link = link.substring(beginPos, endPos) + '/' + appendLink;\n\n    var toprocess = ['excerpt', 'more', 'content'];\n    for(var i = 0; i < toprocess.length; i++){\n      var key = toprocess[i];\n\n      var $ = cheerio.load(data[key], {\n        ignoreWhitespace: false,\n        xmlMode: false,\n        lowerCaseTags: false,\n        decodeEntities: false\n      });\n\n      $('img').each(function(){\n        if ($(this).attr('src')){\n          // For windows style path, we replace '\\' to '/'.\n          var src = $(this).attr('src').replace('\\\\', '/');\n          if(!(/http[s]*.*|\\/\\/.*/.test(src)\n            || /^\\s+\\//.test(src)\n            || /^\\s*\\/uploads|images\\//.test(src))) {\n            // For \"about\" page, the first part of \"src\" can't be removed.\n            // In addition, to support multi-level local directory.\n            var linkArray = link.split('/').filter(function(elem){\n              return elem != '';\n            });\n            var srcArray = src.split('/').filter(function(elem){\n              return elem != '' && elem != '.';\n            });\n            if(srcArray.length > 1)\n            srcArray.shift();\n            src = srcArray.join('/');\n\n            $(this).attr('src', config.root + link + src);\n            console.info&&console.info(\"update link as:-->\"+config.root + link + src);\n          }\n        }else{\n          console.info&&console.info(\"no src attr, skipped...\");\n          console.info&&console.info($(this));\n        }\n      });\n      data[key] = $.html();\n    }\n  }\n});\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"hexo-asset-image\",\n  \"version\": \"0.0.5\",\n  \"description\": \"Give asset image in hexo a absolutely path automatically\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"keywords\": [\n    \"hexo\",\n    \"iamge\",\n    \"asset\",\n    \"path\"\n  ],\n  \"author\": \"xcodebuild\",\n  \"license\": \"MIT\",\n  \"dependencies\": {\n    \"cheerio\": \"^0.19.0\",\n    \"entities\": \"^1.1.2\"\n  }\n}\n"
  }
]