生成静态文件时,hexo更改文件夹结构

时间:2015-06-16 07:25:52

标签: structure directory markdown hexo

首先,感谢Hexo。这是我的问题:

我在Hexo配置文件中将post_asset_folder设置为true。然后我跑:

$ hexo new first

然后:

$ ls source/_posts/

  

first / first.md hello-world.md

我在pic.png中添加了一张名为source/_posts/first的图片,并在source/_posts/first.md中写了一些内容,如下所示:

title: first

date: 2015-06-16 13:42:29

tags:

---

picture blow ^_^

![pic](first/pic.png)

然后:

$ hexo g

$ hexo s

我打开http://0.0.0.0:4000/,但我看不到pic.png的内容。

我检查了文件夹public/2015/06/16/first/。我发现文件夹public/2015/06/16/和文件夹source/_posts/之间存在一些差异。

  1. 文件夹public/2015/06/16/

    的结构
    - public/2015/06/16/
        `- first
            `- pic.png
            `- first.md
        `- hello-world
            `-hello-world.md
    
  2. 文件夹source/_posts/

    的结构
    - source/_posts/
        `- first
            `- first
                `pic.png
            `- first.md
        `- hello-world
            `-hello-world.md
    
  3. 如何统一我可以在markdowmindex.html中获得相同路径的路径格式。

5 个答案:

答案 0 :(得分:1)

您可以(遗憾地)不在您选择的降价编辑器中显示图像呈现的HTML文件。要使其在渲染版本中工作,您必须像下面这样解决:![](cat.jpg)

  1. post_asset_folder: true
  2. 中设置_config.yml
  3. 使用hexo new post "Some New Post"
  4. 创建新帖子
  5. 将图片放在source/_posts/Some-New-Post/中,例如source/_posts/Some-New-Post/cat.jpg
  6. 使用![](cat.jpg)
  7. 在帖子中显示图片

答案 1 :(得分:0)

在你的帖子中,只需使用 pic.png ,但不能 first / pic.png

hexo会将文件与html文件一起放在资产文件夹中

答案 2 :(得分:0)

这不是创建带照片的帖子的正确方法。将post_assets_folder设置为true,然后按以下步骤操作:
1.运行hexo new post "YOUR TITLE"(文件夹YOUR-TITLE,并在YOUR-TITLE.md)创建文件source/_posts 2.将照片放在source/_posts/YOUR-TITLE文件夹中 3.要链接帖子中的照片,您必须使用相对网址,因此您的网址将直接显示您照片的标题(例如:pic.png

答案 3 :(得分:0)

问题中的目录结构不正确。

以下是我的步骤:

  1. 创建帖子:

    hexo new first
    
  2. 修改帖子'Markdown文件:

    vim source/_post/first.md
    

    first.md的内容:

    title: first
    
    date: 2015-06-16 13:42:29
    
    tags:
    
    ---
    
    picture blow ^_^
    
    ![pic](first/pic.png)
    
  3. 将图片pic.png添加到source/_post/first文件夹

  4. 现在source目录的结构如下所示:

    - source
        `- _posts/
            `- first
                `pic.png
            `- first.md
            `- hello-world.md
    
  5. 运行hexo g && hexo s

  6. 在浏览器中打开http://0.0.0.0;请注意pic.png未显示
  7. public目录如下所示:

    - public
        `- 2015
            `- 06
                `- 16
                    `- first
                        `- index.html
                        `- pic.png
                    `- hello-world
                        `- index.html
    
  8. 从那里,您可以看到pic.png文件已从子目录first/first移至first

    因此,为了使其工作,您需要引用相对于帖子目录的文件(first,例如{% asset_img 'pic.png' %}应该这样做。)

答案 4 :(得分:0)

在hexo 3中,引用资产图像的推荐方法是使用标记插件,而不是降价。查看docs

{% asset_img "fudan-advanced-math-01-01.PNG"%} 
![](fudan-advanced-math-01-01.PNG) // doesn't work well
相关问题