【问题标题】:hexo change folder structure when generate static fileshexo生成静态文件时改变文件夹结构
【发布时间】:2015-08-31 21:35:26
【问题描述】:

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

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

$ hexo new first.

然后:

$ ls source/_posts/

first/first.md hello-world.md

我在source/_posts/first 中添加了一张名为pic.png 的图片,并在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
  1. 文件夹结构source/_posts/
.
└── source/_posts/
    ├── first
    │   ├── first
    │   │   └── pic.png
    │   └── first.md
    └── hello-world
        └── hello-world.md 

如何统一路径格式,使markdowmindex.html 可以得到相同的路径。

【问题讨论】:

    标签: structure directory markdown hexo


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      在您的帖子中,只使用 pic.png,而不是 first/pic.png

      hexo会将asset文件夹中的文件和html文件放在一起

      【讨论】:

      • 我会在markdowm文件中写入first/pic.png,并通过这种方式修改为pic.png。我希望有一种方法可以让事情变得更容易,比如让 hexo 生成相同的文件夹结构。
      【解决方案3】:

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

      【讨论】:

      • 我的步骤和你的一样。第三步,我在md文件中写了first/pic.png。它并没有像我说的那样工作。
      • 你能再给我看一下source/_posts 的结构吗,因为我认为你的帖子有误。一个文件夹不能不包含您写的子文件夹(用于照片)及其帖子(.md 文件)。
      • 看我的评论@你。
      • 感谢您的帮助,我找到了解决方案,我将图像存储在第三方平台中。
      【解决方案4】:

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

      这是我的步骤:

      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
        

      从那里您可以看到pic.png 文件已从子目录first/first 移动到first

      因此,为了使其正常工作,您需要引用相对于 post 目录的文件(first,例如 {% asset_img 'pic.png' %} 应该可以解决问题)。

      【讨论】:

        【解决方案5】:

        在 hexo 3 中,推荐的引用资产图像的方法是通过标签插件,而不是 markdown。检查docs

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

        【讨论】:

          猜你喜欢
          • 2022-07-11
          • 1970-01-01
          • 2018-07-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-03-31
          • 2012-11-10
          相关资源
          最近更新 更多