E
E
evil_eyes2016-11-24 21:15:37
Node.js
evil_eyes, 2016-11-24 21:15:37

Parsing html and code replacement, where to dig?

Hello! Such a situation: I use gulp in my projects (standard tools: jade, scssm, concat, browser-sync, minify, etc.).
There was a task: you need a plugin, or something, that would run through all the folders in a certain directory and process only html files, and find certain given pieces of code in them and change them to certain given other pieces of code and overwrite html files with already changed pieces of code (or spit them out somewhere separately). I suspect that such a plugin should be under gulp, but I can't figure out the abundance of plugins and the often modest description of them.
And the second question: I understand that it is possible to implement such parsing stupidly through the nodejs console? At the same time, indicating pieces of code to be replaced in the console. Or am I wrong and this is the wrong step? But for this it is already necessary to write your own module specifically for the Node, as far as I understand.
To summarize: you need to go through all the specified folders, find each .html, find the given pieces of code in it (for example:

<script src="old.js></script> <a href=http://oldlink.com"></a>
) and replace them with another code (
<script src="NEW.js></script> <a href=http://NEWlink.com">
, respectively).
In general, I need advice, otherwise I'm already completely confused.
PS I use Sublime/Atom/Brackets, maybe there are some plugins for them?
Thank you for your attention.
-----------------------------
PSS I forgot to say that I'm just learning to write my "configs" for gulp, about how and what should I understand, but I am by no means an expert in this matter.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pomeo, 2016-11-24
@evil_eyes

It would be better if you wrote what you have for os. Without gulp, sed would solve the problem for you.
Google search for "gulp sed" brings up the first https://github.com/lazd/gulp-replace

M
moserevg, 2016-11-24
@moserevg

If I understood correctly, you need gulp-inject

F
Fadi Haj, 2016-11-24
@fdhaj

For such a simple task, you can write a bash script.
Example:

for file in templates/**/*.html
do
    sed -i "s/old/NEW/g" "${file}"
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question