Linking to assets in Vuepress - vuepress

I want to keep related assets in the same folder as the relevant markdown.
+-- README.md
+-- some-folder
| +-- index.md
| +-- img
| +-- example-screenshot.png
Displaying the image on the page is fine using:
![Some Alt Text](./img/example-screenshot.png)
The location of the files when vuepress build is run is updated: /assets/img/my-new-img.ac30dec4.jpg
However, if I just want a link to the screenshot the, the url isn't being processed correctly:
[See screenshot](./img/example-screenshot.png)
The link comes out as '/some-folder/img/my-new-img.jpg'
Not sure if this would be a bug, feature request, or if I'm not doing it correctly.

You are using a relative URL, this has as a benefit that files are compiled into Vue components and processed by webpack. Your image is basically compiled, versioned (because of caching), copied to a new directory, plus the path has been updated.
You can read more here https://vuepress.vuejs.org/guide/assets.html#asset-handling
If you don't want that to happen, you can put your images in .vuepress/public/.
Afterward, you can reference it as ![img](/example-screenshot.png) or if you use the img/ subdirectory as ![img](/img/example-screenshot.png).
It becomes slightly more difficult if you have set a custom base in your config.js. However, you can rely in that case on html with something like <img :src="$withBase('/foo.png')" alt="foo">

If you have the following file structure and want to keep the images in the respective folders and reference in custom components - you can also use an alias in .vuepress/config.js. I think this is helpful when you want to keep things organized per group folder rather than in the public folder.
Folder Structure
docs/
--.vuepress/
----/layouts/
------/Tools.vue
----/Tools
------/wrench/
--------/wrench.png
--------/README.md
config.js
configureWebpack: {
resolve: {
alias: {
'#tools': '/docs/Tools/'
}
}
}
README.md
<template>
<Layout>
<template slot="page-top"> // this ensures you have the global navbar
<!-- My page content here -->
</template>
</Layout>
</template>
<script>
import Layout from "#theme/layouts/Tools.vue";
export default {
components: { Layout }
};
</script>
Tools.vue
<template>
<div id="Tools">
<img src="~#tools/wrench/wrench.png" />
</div>
</template>

Related

How to configure AdminLTE 3 javascript links with laravel 6?

I configured AdminLTE with laravel 6. I am getting error 404 in console. I used NPM to install adminLTE, my adminlte files are in node_modules folder. Kindly look at the link if I am doing it right.
File structure I have
|-> node_modules
|-> resources
|-> views
|-> admin
|-> users
|->index.blade.php
A link from index.blade.php
<script src="../../node_modules/admin-lte/plugins/jquery/jquery.min.js"></script>
Why are you doing like this? Your jquery and other necessary plugins are already included in app.js file. Just run npm run dev. And then include the public js/app.js to your index.blade.php file.
If you need extra plugins just include them in bootstrap.js file.
Note:If your app.js is empty just run composer require laravel/ui.It will create app.js and bootstrap.js with necessary configraton.

How to access a js file outside the public folder?

I was trying to register a vue component in the app.js file from a laravel project but I just can't seem to find the right path for the app.js, there are two files with app.js filenames. Here is my file structure:
public
css
js
app.js
resources
js
components
Articles.vue
ExampleComponent.Vue
app.js
bootstrap.js
Here is where I imported my app.js file to my blade file:
<body>
<div id="app">
<articles>
</articles>
</div>
<script type="text/javascript" src="{{ assets('js/app.js') }}"></script>
</body>
The problem is I want to access the second app.js file which is in the resources folder, but the above code keeps giving me the first app.js file which is in the public folder.
I tried giving it the absolute path to the file using this code URL::asset('resources/js/app.js')
This gives me a url like localhost:8000/resources/js/app.js which is the correct file location but somehow this link leads to a 404 page. So is there any other way to access the file?
Thanks
Firstly
localhost:8000/something always refer to something in the public directory. So, you cannot reference your resource/js/app.js in your blade file as js file.
Secondly
Actually you don't need to use the resource/js/app.js file in your blade. If you even do so, the code won't work. Because the codes in resources/js/app.js are un-compiled. You need to compile them and use them in blade files. So, where is the compiled file? It's actually the public/js/app.js file. This file is the compiled version of your resource/js/app.js.
The problem is every time you change a js file inside resource, you need to re-compile the js codes. All those codes will be merged together and will be copied in public/js/app.js.
How to compile?
Before compiling your js code you need to make sure you have installed your frontend dependencies correctly by running the npm install command.
Then if all dependencies are installed you can compile your code using the command
npm run dev for development level compile
npm run production for production level(minified and secured) compile.
If you don't want to run the npm run dev command every time you change a file, then you can run npm run watch command. This command will watch if any js file changed. If changed it will compile automatically.

How to compile all scss files located in different folders?

I have a file structure as follows:
all_skins
|— 1
|— css
|- _skinVariables.scss
|— file.scss
|— file.css
|— 2
|— css
|- _skinVariables.scss
|— file.scss
|— file.css
|— 3
|— css
|- _skinVariables.scss
|— file.scss
|— file.css
common_css
| _specificCode.scss
| _otherCode.scss
Inside my scss file for each "skin" I'm importing some general scss partials such as _skinsVariables and _specificCode. The _skinVariables partial changes for each skin, and the _specificCode is a general partial reused in all the scss files located outside the all_skins directory.
The problem is that whenever I make a change in the specificCode partial file, I need to recompile manually each scss file to generate the new css with the modified code.
I'm using PhpStorm's file watcher, so any change to the specific scss file triggers the watcher, but a modification to the included _specificCode (or any included partial) doesn't trigger it.
Is there any way to compile all the scss files inside a parent folder? There are over 30 of these numbered sub-folders, so doing it by hand is time consuming.
Any solution using command line, PhpStorm itself, or other software such as grunt will do for me (least desired).
Edit:
The file.scss would be as follows:
#import "skinVariables";
#import "../../../common_css/specificCode"
To be a bit clearer, the problem is that I have the partials included in all my file.scss, to make life easier most of the code comes from the partials.
When I modify a partial that is imported in all the files, such as _specificCode.scss, I would need all the file.scss to be re-compiled, but this doesn't happen.
The way the watchers seem to work at the moment is that they're triggered only when a modification is done to the file.scss itself, not to the partial that is being included.
Any work around this?
So now you have the file watcher set to watch the open files and in case of modification it should compile ONLY the file itself.
What you need is to set your scss transpiler to compile the /all_skins/1/css/file.scss, /all_skins/2/css/file.scss, etc., but I don't know if the ruby transpiler you're using is capable of this setting.
I solved something similar with http://gulpjs.com (Grunt alternative) with Gulpfile.js config like this (altered to your paths):
gulp.task('styles', function() {
return gulp.src([
'all_skins/**/*.scss'
])
.pipe($.sass())
.pipe($.autoprefixer('last 3 version'));
});
Then set a PhpStorm's file watcher to watch whole all_skins and common_css folder (can be set by "scopes") and run gulp task named "styles" and it should work.

Downloaded image dont show it in maven project

I have a maven project and i download images dinamicly in folder \src\main\webapp\images\, but dont show it in browser. Example:
|- src
|- main
|- java
|- resources
|- webapps
|- images
|- image1.jpg (fixed)
|- image2.jpg (fixed)
|- image3.jpg (downloaded with my app)
If i show image1.jpg or image2.jpg works perfecty, but if i try show image3.jpg dont works:
<img src="images/image1.jpg" /> <!-- Works -->
<img src="images/image2.jpg" /> <!-- Works -->
<img src="images/image3.jpg" /> <!-- Not Works -->
Any idea?
Thanks.
Well... as far as I understand your are modifying your web-app resources at runtime. It works fine in eclipse because eclipse do kind of hot-deployement when your workspace is modified (i.e. when a new file is added in your webapp dir it is automatically available as a webresource for your appserver).
I don't think it's a good design. Imagine you download one image, then redeploy your webapp: the downloaded image will be lost.
Instead of putting your downloaded images in your web app resources: put them somewhere else (outside the war hierarchy, maybe in a directory managed by your web server)

How to add JS/CSS files to Joomla modules?

I am starting out with Joomla and am writing a simple Joomla module. I am using some custom CSS and JS in my module. Now when I distribute this module I need my JS/CSS files to go with the ZIP. I have added my files in my module ZIP file.
This is what i need to know -
How do I refer to these CSS/JS files in my module so that even if I distribute the module as a zip i would not have to send the css/js files separately?
I tried looking at different solutions including
http://www.howtojoomla.net/how-tos/development/how-to-add-cssjavascript-to-your-joomla-extension But I was not able to figure out what the URL for the JS/CSS file should be?
I am using Joomla 1.7 hosted on a cloud hosting site.
Thanks
I'd say that the HowToJoomla Site's article pretty much sums up the process.
Here is the process with a few more steps added - hopefully this will help.
I am assuming you have got as far as packaging your extension and have been able to get your css and javascript files to install on the server. They may be in your module folder, or probably more correctly they should be within your modules sub-folder under the /media/ folder.
If after installing the module you can not locate your css and js files it is because you haven't referenced them correctly within your component's xml installation file. This page contains info about the xml installation / manifest file for 1.6/1.7 add-ons although it is for a component: http://docs.joomla.org/Developing_a_Model-View-Controller_%28MVC%29_Component_for_Joomla!1.6_-_Part_01 they are very similar.
Either way - find your files within Joomla's folder structure and make a note of their relative path from the root of the website - ie the folder containing configuration.php
Now somewhere within your module's php - add the line that gets a reference to the JDocument object.
$document = JFactory::getDocument();
Now add the line that adds your javascript to the html head area:
$document->addScript('url/to/my/script.js');
obviously replace 'url/to/my/script.js' with the actual relative path to your javascript.
Now add the line that adds your css to the html head:
$document->addStyleSheet('url/to/my/stylesheet.css');
again adjust the path - it may for example be media/mod_mymodule/mymodule.css (if your module were called 'mymodule').
Only things to be aware of are that you need to add these lineswithin executable php tags NOT within a html area after exiting php mode.
You could add your js/css files to /media folder.
http://docs.joomla.org/Manifest_files#Media_files
Just add to your manifest file:
<files>
...
</files>
<media folder="media" destination="mod_your_module">
<folder>css</folder>
<folder>js</folder>
</media>
Inside your installable package, you should now have the /media folder.
Then add to view file:
$doc =& JFactory::getDocument();
$doc->addScript("/media/mod_your_module/js/script.js");
This article explains the benefits of this approach:
http://blog.joomlatools.com/2008/09/hidden-feature-joomlas-media-folder.html
You could use:
JHTML::script('modules/mod_your_module/js/script.js');
JHTML::stylesheet('modules/mod_your_module/css/stylesheet.css');
This example does not require JFactory::getDocument()
$document = JFactory::getDocument();
$modulePath = JURI::base() . 'modules/mod_your_module_name/';
//Adding JS Files
$document->addScript($modulePath.'js/myscript.js');
//Adding CSS Files
$document->addStyleSheet($modulePath.'css/style.css');
<script type="text/javascript" src="<?php echo JURI::BASE()?>modules/your_module_name/js/your_js_file"></script>
for Css:
<link href="<?php echo JURI::BASE()?>modules/your_module_name/css/your_css _file" type="text/css" media="all" rel="stylesheet">

Resources