First of all, thanks Hexo. Here is my question:
I set post_asset_folder to true in the Hexo configuration file. Then I run:
$ hexo new first.
then:
$ ls source/_posts/
first/ first.md hello-world.md
I added a pic named pic.png into source/_posts/first and wrote something in source/_posts/first.md like the following:
title: first
date: 2015-06-16 13:42:29
tags:
---
picture blow ^_^
![pic](first/pic.png)
Then:
$ hexo g
$ hexo s
I open http://0.0.0.0:4000/, but i coundn't see the content of pic.png.
I checked the folder public/2015/06/16/first/. I found there is some diffrience between folder public/2015/06/16/ and folder source/_posts/.
structure of folder public/2015/06/16/
.
└── public/2015/06/16/
├── first
│ ├── pic.png
│ └── first.md
└── hello-world
└── hello-world.md
structure of folder source/_posts/
.
└── source/_posts/
├── first
│ ├── first
│ │ └── pic.png
│ └── first.md
└── hello-world
└── hello-world.md
How can i unify the path format that i could get same path in markdowm and index.html.
You can (sadly) not display an image in your markdown editor of choice and the rendered HTML file. To make it work in in the rendered version, you have to address it like this: ![](cat.jpg).
Set post_asset_folder: true in _config.yml
Create new post with hexo new post "Some New Post"
Place image in source/_posts/Some-New-Post/, e.g. source/_posts/Some-New-Post/cat.jpg
Display image in post with ![](cat.jpg)
in your post, just use pic.png, but not first/pic.png
hexo will put the files in asset folder with html file together
This is not the right way to create post with photos. Make that post_assets_folder is set to true and follow these steps :
1. Run hexo new post "YOUR TITLE" (a folder YOUR-TITLE and a file YOUR-TITLE.md are created in source/_posts)
2. Place your photos in source/_posts/YOUR-TITLE folder
3. To link photos in a post, you have to use relative url, so your url will be directly the title of your photos (e.g: pic.png)
The directory structure in the question is incorrect.
Here are my steps:
create a post:
hexo new first
modify the post' Markdown file:
vim source/_post/first.md
content of first.md:
title: first
date: 2015-06-16 13:42:29
tags:
---
picture blow ^_^
![pic](first/pic.png)
add image pic.png to the source/_post/first folder
now the structure of source directory looks like this:
- source
`- _posts/
`- first
`pic.png
`- first.md
`- hello-world.md
run hexo g && hexo s
open http://0.0.0.0 in a browser; note that the pic.png is not shown
the public directory looks like this:
- public
`- 2015
`- 06
`- 16
`- first
`- index.html
`- pic.png
`- hello-world
`- index.html
From there you can see that the pic.png file was moved from the subdirectory first/first to first.
So in order to make it work, you need to refer to the file relative to the post directory (first, e.g. {% asset_img 'pic.png' %} should do the trick).
in hexo 3 the recommended way to reference a asset image is by tag plugin, rather than markdown. Check the docs
{% asset_img "fudan-advanced-math-01-01.PNG"%}
![](fudan-advanced-math-01-01.PNG) // doesn't work well
Related
I have a Vue project with multiple pages where I use rollupOptions.input to specify them as entry points:
rollupOptions: {
input: {
main: resolve(__dirname, "index.html"),
subpage1: resolve(__dirname, "subpage1/index.html"),
subpage2: resolve(__dirname, "subpage2/index.html")
}
},
The final dist folder will be deployed at a subdirectory in a server,
so I then set a base attribute as base: "", to make the assets work for the main index.html . This turns all the paths into something relative like this: <link rel="stylesheet" href="assets/main.35431485.css">. Works for the root index.html but for the subpages, the links look identical. This however doesn't work, because the folder structure is something like:
├── index.html
├── assets
├── main.35431485.css
└── ...
└── subpage1
└── index.html
As such, subpage1/assets/main.35431485.css will simply not work.
Is there a way to tell vite to relatively path its way to the asset folder, even for subpages?
Ideally not using a static parent directory (like with base: "/some/dir/"), but keeping it all relative?
This is a known issue that will be fixed in vite 3.0. There seems to be a fair amount of issues left for the 3.0 release but hopefully it will be released sometime in 2022. Right now the only way is to have a static base path, changing to some SPA approach, or using another build tool.
Edit: vite 3.0 is now released and relative base path is now properly supported. See the docs here.
I'm a little confused on how to make this work and need a better understanding in terms of the ansible side of getting the following done:
I have 500 images and I need to generate a default json config based on the image names. For example:
1.jpg
2.jpg
3.jpg
etc etc
From that list, I need to generate the following:
1.json
2.json
3.json
etc etc
When it's all said and done the directory should have 500 images and 500 json files. I would also like to have that json file as a j2 template so I can pre define some information in the json file based on the project in a group_var.
I know I can do the following to copy the template doing this:
- name: Copy JSON Configuration
ansible.builtin.template:
src: sample.json.j2
dest: /path/to/directory
I'm just lost in the part to generate the list of the json files based on the image list. I have googled some stuff that is maybe the same but what I have found seem way beyond what I needed to get done or I'm not simply understanding it correctly. Thank you for any and all help I really appreciate it!
For example, given the tree
shell> tree test-616
test-616
├── 1.jpg
├── 2.jpg
└── 3.jpg
and the template
shell> cat sample.json.j2
{{ item }}
Find the files and iterate the paths
- find:
path: test-616
register: result
- template:
src: sample.json.j2
dest: "{{ _item }}.json"
loop: "{{ result.files|map(attribute='path')|list }}"
vars:
_item: "{{ item|splitext|first }}"
This will create the files
shell> tree test-616
test-616
├── 1.jpg
├── 1.json
├── 2.jpg
├── 2.json
├── 3.jpg
└── 3.json
I'm following this tutorial: https://docs.realm.io/sync/getting-started-1/react-native-quick-start/step-1-query-based-sync#step-4-create-a-constants-file-and-set-the-realm-instance-address
Many documents including this tutorial refers a src folder, but when I create a React Native project with a command like react-native init MyProject, it doesn't create src folder. Why is that?
Following is my folder structure:
├── App.js
├── android
├── app.json
├── index.js
├── ios
├── node_modules
├── package.json
└── yarn.lock
because react-native-cli do not provide src folder. its up to you, how you design or architect your app. directory structures are upto you and you need to write code accordingly. Generally project specific code always kept in src folder. In your case, there is just one component and App.js is the only file that holds the entire code. but as there will many screens/components you will find it unmanageable. for sake of modularity, src folder is made and used.
App
|
|--src
|
|--assets
|--components
|--screens
|
|--loginScreen.jsx
|--homeScreen.jsx
Just manually create your src folder. It's just used to better organize your project.
I'm running into an annoying problem when using relative path in the init function which cannot be found by the unit test.
Say I have a project structured like:
.
├── conf
│ └── blacklist
├── filter
│ ├── filter.go
│ └── filter_test.go
And in the init function of filter.go, I try to load the blacklist by using relative path conf/blacklist to avoid loading it multiple times.
Since the default working directory is exactly the project root directory, it works well with compiled binary. However filter_test.go will panic by
panic: open conf/blacklist: no such file or directory, becasue go test always uses the package directory as the working directory.
I also referred this solution, which could dynamically build the relative path to find the config file. It did work well until I add the covermode=set flag and try to do some coverage testing. It seems that the covermode would rewrite and generate some middle packages like _obj, which makes the dynamical relative path not working any more.
Has anyone run into the same problem before? I'm still new to golang for a couple of months. Any suggestions will be appreciated.
A simple solution is to run tests using something like SRC_ROOT=$PWD go test and then inside the test that want to access files use os.Getenv("SRC_ROOT").
I have an express app with my dev views in /assets/views. I figure I need to separate development and production views because in production I'll be editing the HTML when I used grunt-contrib-usemin to concat/uglify scripts.
So here's the problem. My current tree:
assets/views
├── 404.html
├── index.html
├── layout.html
├── question_ask.html
└── question_display.html
Ideally, I want my production-ready views to live on the same level as assets. Using grunt-contrib-copy, it seems to copy the whole tree. I currently am putting it into public since I'm not sure how to set my dest to the root of the project.
copy: {
views: {
src: ['assets/views/*.html'],
dest: 'public/'
}
So there are a few questions here:
Is it bad practice to have dev views and production views? If so, is there another way of producing a view that has references to concat/uglified scripts?
How the heck can I use grunt-contrib-copy to copy to the root of my project? I don't want assets/views obviously, I just want a views/* folder that has the contents of what's in assets/views/*.
Thanks!
You need to specify the flatten option which will remove the directory structure from the destination path. See my answer here: Copy all files from directory to another with Grunt.js copy