-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Generated site does not work with local file:// access #387
Comments
Sorry I cannot know what's your question. If you need help, please DON'T ignore the issue template, and provide a reproduced repo anyhow. |
Not sure if it will work, but try setting base to |
@ulivz: Sorry for the lack of information. Here it is:
Steps to reproduce: mkdir bug387
mkdir bug387/subdir
cd bug387
echo "# Link to [subdir](subdir)" > README.md
echo "# Subdirectory page" > subdir/README.md
vuepress build
cd .vuepress/dist
firefox index.html # or chromium-browser for that matter Results:
Expected:
Use case: I want to generate static docs that can be shipped on an USB stick, and can be viewed By manually editing the links in the HTML, I can get it to work. After
Can you please reopen the bug? |
Try |
Exactly the same as above. Asset URLs in subdir refer to "./assets/xxx", when "../assets/xxx" would be correct. |
It could be a bug. I remember that |
I find it, it could be a bug of
So there will always be a |
Issue submitted |
Has this bug been fixed yet? Please re-open! |
This has been my experience trying to get this to work using the following files...
README.md
page2.md
After Any ideas?? |
I did a thing :D vuepress-offlinify |
You can set base to a absolute path ` const basePath = process.env.Node_ENV === 'production' ? path.resolve(__dirname, './dist') : '/'; module.esport = { title: '', base: basePath} ` |
UDPATE: I tried everything in the comments and nothing worked. Opened up #2844 Vuepress is great If you want something that works out of the box and want to get online quickly but I haven't tried it offline 'yet'. I hope that there is an easy solution to this since I do have documentation that I don't want to make available online? |
I code a tool like this: const path = require("path");
const fs = require("fs");
const cheerio = require("cheerio");
const walk = require("walk");
const isAbsoluteUrl = require("is-absolute-url");
const isUrl = require("is-url");
const distPath = fs.realpathSync(process.argv[2]);
const walker = walk.walk(distPath, {
followLinks: false
});
walker.on("file", (root, fileStats, next) => {
const extName = path.extname(fileStats.name);
if (extName !== ".html") {
next();
return;
}
const htmlFile = path.join(root, fileStats.name);
console.log(`Offline ${htmlFile}`);
offlineFile(htmlFile);
next();
});
walker.on("errors", (root, nodeStatsArray, next) => {
next();
});
walker.on("end", () => {
console.log("All Completed");
});
function offlineFile(fileName) {
const htmlContent = fs.readFileSync(fileName, "utf-8");
const $ = cheerio.load(htmlContent);
// CSS
$("link").each((index, element) => {
const attributeValue = $(element).attr("href");
const realAttributeValue = path.join(distPath, attributeValue);
const relativeValue = path.relative(path.dirname(fileName), realAttributeValue);
$(element).attr("href", relativeValue);
});
// JS
$("script").each((index, element) => {
const attributeValue = $(element).attr("src");
const realAttributeValue = path.join(distPath, attributeValue);
const relativeValue = path.relative(path.dirname(fileName), realAttributeValue);
$(element).attr("src", relativeValue);
});
// a.href
$("a").each((index, element) => {
const attributeValue = $(element).attr("href");
if (isUrl(attributeValue)) {
return;
}
let realAttributeValue = path.join(distPath, attributeValue);
if (fs.existsSync(path.join(realAttributeValue, "index.html"))) {
realAttributeValue = path.join(realAttributeValue, "index.html");
}
const relativeValue = path.relative(path.dirname(fileName), realAttributeValue);
$(element).attr("href", relativeValue);
});
// img
$("img").each((index, element) => {
const attributeValue = $(element).attr("src");
if (isAbsoluteUrl(attributeValue)) {
return;
}
if (isUrl(attributeValue)) {
// replace like //example.com/1.png
$(element).attr("src", `https:${attributeValue}`);
} else {
const realAttributeValue = path.join(distPath, attributeValue);
const relativeValue = path.relative(path.dirname(fileName), realAttributeValue);
$(element).attr("src", relativeValue);
}
});
const transformedHtml = $.html();
fs.writeFileSync(fileName, transformedHtml, "utf-8");
} Run it like this: node offline.js dist Some dependencies should be add firstly: yarn add -D cheerio walk is-absolute-url is-url |
I have a project where documentation is used in the field, and an internet connection is often not available. Starting a local web server is also not an option. Most likely the documentation will be shipped on a USB stick or CD-ROM.
Therefore, all links must be relative and point to
./foo/index.html
instead of just./foo
mkdocs does have a config option for this use case:
http://www.mkdocs.org/user-guide/configuration/#use_directory_urls
Is it possible to configure vuepress in the same way?
The text was updated successfully, but these errors were encountered: