question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider to allow to use alternative for public directory

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
PeppeL-Gcommented, Oct 6, 2019

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 src folder (recursively) that does not have the file extension .md and copies them to the same place in the src/.vuepress/public folder when the development server starts (e.g. src/sub-folder/hello.txt is copied to src/.vuepress/public/sub-folder/hello.txt).

Here’s the function that does it (add it too src/.vuepress/config.js and call it there):

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.

5reactions
shigmacommented, Mar 30, 2019

@timaschew @rreinhardt I have drafted a PR for this.

#1494

Read more comments on GitHub >

github_iconTop Results From Across the Web

Consider these Office 365 alternatives to public folders
Microsoft offers several alternatives to public folders for organizations that want to migrate from Exchange Server to Office 365.
Read more >
Public Folder Alternative - MS Exchange
We have been using public folders in our small office (16 users) for approx. 15 years. I have had no issues with them...
Read more >
Windows 10 update, turns off public folder sharing - Server Fault
My question is, is there a better way to share files on Windows 10 Pro which isn't affected by Updates? For example, enable...
Read more >
java - Alternative to requestLegacyExternalStorage and ...
A) The usual way to write to public directories for Android 10 is to use requestLegacyExternalStorage, but this doesn't work if you target ......
Read more >
Storage updates in Android 11
Migrate data to directories that are visible when using scoped storage ... If your app uses the legacy storage model and previously targeted...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found