Skip to content
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

could i config custom @@webRoot or add @@urlRoot ? #183

Open
lacomparte opened this issue Feb 9, 2021 · 6 comments
Open

could i config custom @@webRoot or add @@urlRoot ? #183

lacomparte opened this issue Feb 9, 2021 · 6 comments

Comments

@lacomparte
Copy link

I want to use @@urlRoot (current there's no exist in this package)
Or
custom @@webRoot path.

is it possible?

@dpilafian
Copy link
Collaborator

A web page's URL is dependent on where the page is deployed and how the web server is configured, so the full URL is generally not known when the HTML is generated.

An example use case might help clarify what you're trying to accomplish.

If you actually know the URL ahead of time, you could just create a regular variable named @@urlRoot and set it just like any other regular variable. See the @@name and @@age examples in the Readme.md.

@lacomparte
Copy link
Author

lacomparte commented Feb 10, 2021

@dpilafian
thx for your comment.

i wanna configuration that global var @@some in package

ex)

// some config..
@@some = 'http://path';

// code
<img src="@@some/image.png">

// parsing
<img src="http://path/image.png">

@dpilafian
Copy link
Collaborator

You should be able to do that by setting the some variable in the @@include statement, like:

<!DOCTYPE html>
<html>
  <body>
  @@include("./var.html", { "some": "https://example.com/path" })
  </body>
</html>

@lacomparte
Copy link
Author

@dpilafian
i know :)
but how could i configuration GLOBAL variable in npm package.

@dpilafian
Copy link
Collaborator

dpilafian commented Feb 12, 2021

Here's a real example that I think does what you're asking to do.

It reads package.json into an object and then passes that into the fileInclude() function.

gulpfile.js

import { readFileSync } from 'fs';
...
const pkg = JSON.parse(readFileSync('./package.json'));
...
const webContext = {
   pkg:          pkg,
   released:     released,
   minorVersion: minorVersion,
   gzipSize:     '8 kb gzip',
   title:        pkg.description,  //default page title
   youTube:      linkInfo.youTube,
   jsFiddle:     linkInfo.jsFiddle
   };
...
         gulp.src(['website/static/**/*.html', 'website/root/**/*.html'])
            .pipe(fileInclude({ basepath: '@root', indent: true, context: webContext }))

Now you have access from the templates to everything in package.json.

See the full file at:
https://github.com/dnajs/dna.js/blob/master/gulpfile.js#L38

@lacomparte
Copy link
Author

@dpilafian
thanks u :)
i'll try to your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants