Combining and minifying cross-script variables - minify

I'm looking to combine and minify my JavaScript files. I have a question; on my pages I basically have the same library JS files, and then one 'specific' JS file to run code for that page. I also have variables defined in that specific JS file which are then used elsewhere in the library JS files. For example, I defined var tablename which is then used in a library file to render out a table using what is set as 'tablename'.
My question is, if I combine all of my JavaScript files from all of my pages into one big JS file, and then include that combined/minified file on my pages, then as a result of combining all of the files then that big JS file will have multiple .ready() events and the same variable tablename will be defined multiple times. How is this overcome? Maybe it can't in my situation and I'll need to create a combined/minified file for each of my pages?
Thanks

I think I found the solution; YUI Compressor (that I'm using) doesn't munge global variables, and since my tablename variable will be global (not in a function) then it won't get munged.

Related

Versioning your files to avoid browser cache in PhpStorm

I read the no cache solution and this one on the web here: https://sebhastian.com/javascript-versioning/ where to fix this problem, you needed to add versioning to your util.js file request on the <script> tag. The easiest way would be by adding a query string parameter v as follows:
<script src="util.js?v=1"></script>
This is all gravy but we need to be able to automate the versioning similar to the solution they suggest with Webpack.
In the following webpack.config.js file, the name of the JS file generated by Webpack follows the [name].[contenthash].js pattern. The contenthash will be replaced by a unique hash based on the content of the file.
Anyone with idea how to achieve the same with PhpStorm?

How can I upload images and add Cargo metadata to them at the same time?

I can upload an image, then on its File page I can transclude a Cargo-enabled template that stores some metadata about that image, and later query that template's table in order to create a gallery. However, the manual addition of the template to the File page is tedious and error-prone (e.g. incorrectly naming other pages in various template fields). Is there an extension, perhaps something like Page Forms, that would allow me to simplify this process, so that I could upload an image and populate its metadata on a single page? Is there any simpler workflow in base MediaWiki to achieve this result?
I'm not familiar with Page Form based solution,
What i've done in a similar case (added a templates to 3 sets of ~1k pages) is to use pywikibot (its a library that allows you to do some automated processes in your mediawiki, that an external tool).
The solution is depend on your template, Does your template receive any arguments?
Template without arguments, its enough just to add "{{My_Template}}" to the page, You can achieve this with pywikibot's add text.py script
Template with arguments, that more complicated, In this case i would write a simple python script that will use pywikibot and add the required text (There are several options here)
2.1. Add of relevant files to category with category script, Then in your script iterate over all pages in the category using:
"from pywikibot import pagegenerators" and
"pagegenerators.CategorizedPageGenerator"
2.2. Using:
"pagegenerators.SearchPageGenerator" and passing a namespace + filtering the files you want by predefine knowledge.
BTW, if you are uploading many files, you can use BatchUpload

PhpStorm: how to add watcher on 1 JS file only and not on ALL JS files?

1) How to add a watcher on 1 file ONLY ?
The goal is to put a obfuscator on 1 JS file only (the main.js) : I was unable to do that: obfuscation is applied to ANY JS file I do modify.
2) How to avoid infinite recurrent rules ?
I have 2 watchers right now:
minification on JS files
obfuscation on JS files
Problem is: PhpStorm creates infinite .min.obf.min.obf...js : it looks it applies these 2 rules in endless.
Use Scope field to limit the watched files: create custom Scope that will include only desired file(s) and/or folders and use it there in File Watcher.
Scope can accept both "include" and "exclude" patterns at the same time so it's very flexible in filtering the files.
The same approach for your second issue -- use scope to not to process already processed files.
For example: https://stackoverflow.com/a/24938053/783119
The alternative to having 2 separate File Watchers is creating some batch/shell script that will do that minification + obfuscation and use it as a program in File Watcher.
Another option -- use build tools (Grunt/Gulp or alike) and call appropriate task there.

in Batch:keep functions in the file they are used in, or keep functions in function-specific files

About a week ago I started making a small batch text/turn-based rpg.
Currently what I'm doing is putting all the functions that are used in a file in that file, i.e I have a file named 'Init.bat' I put all the display/logic/arithmetic/validation/variable-functions in it. What I'm wondering is.. would it be better to put the functions in their own file, i.e file for display/logic/etc, or continue what I'm doing now?
The only files that are 'working' are: Classes.bat,Init.bat,PlayerInfo.bat
https://github.com/Ravkrat/batchrpg/tree/fixingInit <-latest build
(hopefully its ok for me to link to GitHub.. the batch file is large now and don't want to make this post to long)
TL;DR
separate functions from the file they are used in and put them in function specific files,or keep functions in the file that uses them.

customizing `org-publish-project-alist`

I'm trying to publish webpage using org-mode. Two questions:
Is there a way to "sync" the org-mode files in the base-directory and the html files in the publishing-directory? Specifically, if I delete an org file in the base-directory, can I get org-publish-html to delete the corresponding file in the html directory also?
If I have pages within subdirectories, how can I specify a single .css file in the root directory to be used for the style sheet? For instance, my directory structure is as follows:
public_html/
css/
mystyle.css
index.html
subdir/
index.html
With the following specifications in org-publish-project-alist (this is just a subset) --
:publishing-directory "public_html"
:style "<link rel=\"stylesheet\" href=\"css/mystyle.css\" type=\"text/css\"/>"
mystyle.css is used by public_html/index.html but not by public_html/subdir/index.html. Is there a simple remedy to this (I want the style sheet to be used by both/all files in subdirectories)?
Thanks much ~
There is no straightforward way of doing this. Org-mode doesn't know (or care) about the location to which it is publishing - it just sends things there and makes sure the correct directory structure exists. There is a hook in the publishing process that gets called after the files have been pushed to their published location. This is controlled by setting the :completion-function property in your org-publish-project-alist. You could use this hook to write a function that compares the *.org files in your base-dir and subdirectories to the accompanying *.html published files, and remove those *.html files that don't have an accompanying *.org file.
I suspect this will be most easily accomplished by making your Lisp completion-function call a shell script that removes the necessary files. If you are doing something fancy with the :include, :exclude, or :base-extension properties, you'll likely want your completion-function to grab the pertinent information from the plist and then pass them to your shell script. This org-mode page has an example completion-function that shows how to get property values for the org-publish-project-alist. You would then need to pass them to your shell script.
There are several ways to do this. Perhaps the simplest is to just override the default style sheet in each file with a line such as:
#+STYLE: <link rel="stylesheet" type="text/css" href="../stylesheet.css" />
for your first level of subdirectory files, and keep adding ../ as you get deeper in the directory structure.
Another possibility is generate generic template files for each level within the directory tree. This org-mode page gives a nice example of how to set this up.
Lastly, another option is to use the :preparation-function property of org-publish-project-alist to define a function that will automatically change the style file for each file. Again, this is probably best done by having the Lisp preparation-function call a shell script to parse the files. I could imagine doing this with the Unix sed program to find a regular expression denoted something like href="#MYLOC#/stylesheet.css" /> and substitute the stuff between #'s with the appropriate level within the directory tree. This seems like overkill, given the other options.