hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.21k stars 4.82k forks source link

Feature Request: Allow templates to get assets referenced in a post and their order #2158

Closed xunnanxu closed 6 years ago

xunnanxu commented 8 years ago

Environment Info

Hexo version 3.2.2

Plugin version(npm ls --depth 0)

+-- hexo@3.2.2
+-- hexo-deployer-git@0.2.0
+-- hexo-generator-archive@0.1.4
+-- hexo-generator-category@0.1.3
+-- hexo-generator-feed@1.2.0
+-- hexo-generator-index@0.2.0
+-- hexo-generator-tag@0.2.0
+-- hexo-renderer-ejs@0.2.0
+-- hexo-renderer-marked@0.2.11
+-- hexo-renderer-stylus@0.3.1
+-- hexo-server@0.2.0

Feature Request

Allow templates to get assets referenced in a post and their order

Use Case

Right now templates don't know what assets are used in posts (e.g. those referenced by asset_img). It would be nice if we can keep a record of asset reference calls and their order. That way, a template can auto generate the thumbnail for a post from the first referenced image asset, for example.

Note this might be against the design since it would require tag plugins to have side effects. An alternative may be is to let template code to trigger tag plugin code in post front-matter, e.g.:

thumbnail: <% asset_img blah.png %>

Template code:

var link = post.thumbnail;
if (hasTagPlugin(link)) {
  link = Tag.eval(link);
}  // link = '/url/to/post/blah.png'
stale[bot] commented 6 years ago

This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs. Thank you for your contributions.