-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Consider to allow to use alternative for public directory #1491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So you want to have a file structure as below:
And in  And the
Am I right? |
Oh, thanks for the examples, I should have provided them ;)
Yes, exactly! |
I also would love to see this functionality in place but I think it would be more expansive without the prerequisite that the resource be referenced via an image tag. The case I'd like to have addressed: file structure:
and in
so that dist looks like:
|
Yes, that should work as well, so basically all kind of relative URLs to resources (images, audio, video, etc.) BTW: @rreinhardt you have two typos: |
@timaschew @rreinhardt I have drafted a PR for this. |
This feature has still not been added to VuePress? @shigma Maybe you should release the plugin as an npm package so we can start using it? |
I'm not trying to be ungrateful (I can't complain about free stuff), but I've waited for this way too long now and can't wait anymore. Instead, I've come up with my own solution, which simply looks for all files in the Here's the function that does it (add it too const fs = require('fs')
const path = require('path')
function copyStaticFilesToPublic(){
const doNotCopyFilenames = [
new RegExp("^.*\\.md$"),
]
const doNotCopyFolderNames = [
new RegExp("^\\.vuepress$")
]
const pathToPublicFolder = path.resolve(__dirname, "public")
const pathToSrcFolder = path.resolve(__dirname, "../")
if(fs.existsSync(pathToPublicFolder)){
fs.rmdirSync(pathToPublicFolder, {recursive: true}) // Requires latest version of node.
}
copyAllStaticFiles(pathToSrcFolder, pathToPublicFolder)
function copyAllStaticFiles(pathToSourceFolder, pathToDestinationFolder){
if(!fs.existsSync(pathToDestinationFolder)){
fs.mkdirSync(pathToDestinationFolder)
}
const names = fs.readdirSync(
pathToSourceFolder
)
for(const name of names){
const pathToSource = path.resolve(
pathToSourceFolder,
name
)
const pathToDestination = path.resolve(
pathToDestinationFolder,
name
)
if(fs.lstatSync(pathToSource).isDirectory()){
if(!doNotCopyFolderNames.some(regexp => regexp.test(name))){
copyAllStaticFiles(pathToSource, pathToDestination)
}
}else{
if(!doNotCopyFilenames.some(regexp => regexp.test(name))){
fs.copyFileSync(pathToSource, pathToDestination)
}
}
}
}
} This works great for me, so I share this piece of code if anyone else is in the same situation as me and in need of a quick fix. Remember that the files are only copied when the development server starts, so adding/changing static files after that requires a restart. |
I am a newcomer to VuePress and got my first site published today. https://akauppi.github.io/Kotka/ Found it weird at build steps that so many assets seem to get renamed and pushes to Not using |
Feature request
What problem does this feature solve?
The problem is that images and other resources which are referenced in markdown files won't work any other environment (on GitHub, GitLab, local preview tools). Because the resources need to be placed into the .vuepress/public directory, but the URL won't include neither .vuepress nor public.
This is really weird.
// edit
Also this will be much easier for everyone who is migrating to VuePress, for instance from GitBook.
What does the proposed API look like?
Allow to put images and other resources next to the markdown files instead of forcing to put them into .vuepress/public.
How should this be implemented in your opinion?
For the
vuepress build
command just passthrough all files which are have not a markdown file extension. This is the only file types you're expecting, right? Other files, like styles or vue components live somewhere else, so they are not affected.Are you willing to work on this yourself?
Sure, let me know if you agree in general with this idea.
The text was updated successfully, but these errors were encountered: