hexo icon indicating copy to clipboard operation
hexo copied to clipboard

如何自定义新建页面类型

Open meowtech opened this issue 12 years ago • 12 comments

  1. 首先,单纯在**scaffolds中新建newtype.md**文件是不行的,
hexo new newtype filename 

虽然成功建立了新类型的MD文件,但生成网页的时候,无法正常显示。 2. 我发现

hexo new post filename

和

hexo new draft filename

命令,是分别新建在**source/_post和source/_draft**两个文件夹里的,这里面的建立机制是怎样的?如果知道了这个,前一个问题也就迎刃而解了。 p.s.好吧,其实这两个问的是同一个问题。 求各位大侠解答!!!

meowtech avatar May 09 '14 06:05 meowtech

Why did you post the exactly same issue twice? Did you know there's a Edit button at the top-right corner?

tommy351 avatar May 09 '14 06:05 tommy351

scallfold 目录不是用来放文章 Markdown 文件的,而是用来设置某个 layout 每一次用 hexo new 命令时 front-matters 的默认配置。

_post 目录和 _draft 目录分别用来放要发布的文章,和暂时不要发布的草稿。这个你应该清楚。我不太理解你想了解什么“建立机制”。

wzpan avatar May 09 '14 06:05 wzpan

@tommy351 Sorry for that ,i wanted to add a "question" tag to the issue , so i close the first one and post twice , though i failed again...

meowtech avatar May 10 '14 06:05 meowtech

@wzpan

  1. 首先,我知道scalfold不是用来存放文章的,它里面存放的是新建文章时各类型对应的初始化参数,如果你看过的话,你会发现里面的文件类型恰好也是_.md_,这点你误会我了。
  2. 我要问的问题,源自于我想实现的功能。打个比方,我想新建一个**media类型,我想在里面预设好插入视频的<video post="" src="">...</video>代码,这样我以后只需要运行hexo new media newfilename**就不用每次都额外填写了。 不知道这次我表达清楚了没有,多谢解答!

meowtech avatar May 10 '14 06:05 meowtech

这个不是完全通过 scaffold 实现。根据你的需求,你可以选择以下任意一种方式:

  1. 在 front-matter 自定义一个变量,用于指定视频路径。添加 media 布局根据该变量生成最终代码。你可以设定 scaffold 让该布局默认添加该变量;
  2. 通过 tag plugins 生成最终代码。这种方式更加灵活。

wzpan avatar May 10 '14 06:05 wzpan

@wzpan 多谢帮助!听上去都是好方法。 不过我都不太理解,你能说具体一些吗? 或者等我先尝试一下,过段时间再请教。

meowtech avatar May 10 '14 11:05 meowtech

@wzpan 有时间能讲解一下这两种方法怎么实现吗? 不胜感激~

meowtech avatar May 13 '14 11:05 meowtech

如 @wzpan 所說的,在 front-matter 中寫入影片路徑,例如:

media: path/to/my/video.mp4

之後便能在主題內取得該變數的內容:

<%= page.media %>
// path/to/my/video.mp4

tommy351 avatar May 13 '14 11:05 tommy351

Thank @tommy351 .

@lowboy , what you want to know is:

  1. how to define front-matter variables and how to read their values at your theme;
  2. how to write tag plugins.

These two are both clearly clarified at Hexo's document.

Alternatively you can take a look at the source code of hexo-theme-freemind. It provides 3 custom front-matter variables and 5 extra tag plugins.

wzpan avatar May 13 '14 12:05 wzpan

Thank @tommy351 that is a good way. Also thank @wzpan ,

  1. I've already know how to write some front-matter variables ,    but the question is that some theme only provide a limited number of front-matter  settings , which fails to satisfy my need.
  2. What I want to know is how to do customization within any theme without too much help   of a particular plugin or something else .
  3. I want to know how to do it by the way of modifing some *.ejs and *.styl files ,  and i am still trying now.   Yet thanks again!

meowtech avatar May 13 '14 13:05 meowtech

That's why I ask you to read the source code of my theme, not just use it.

wzpan avatar May 13 '14 23:05 wzpan

Thank @wzpan , I am working on it , and your theme is one of the best ~

meowtech avatar May 13 '14 23:05 meowtech