-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2f7a75b
Showing
10 changed files
with
492 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# CRAFT ENVIRONMENT | ||
.env.php | ||
.env.sh | ||
.env | ||
|
||
# COMPOSER | ||
/vendor | ||
|
||
# BUILD FILES | ||
/bower_components/* | ||
/node_modules/* | ||
/build/* | ||
/yarn-error.log | ||
|
||
# MISC FILES | ||
.cache | ||
.DS_Store | ||
.idea | ||
.project | ||
.settings | ||
*.esproj | ||
*.sublime-workspace | ||
*.sublime-project | ||
*.tmproj | ||
*.tmproject | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
config.codekit3 | ||
prepros-6.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# NSM Asset Rev Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## 0.0.1 - 2017.06.05 | ||
### Added | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Newism | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# NSM Asset Rev plugin for Craft CMS 3.x | ||
|
||
Rev asset urls with date modified timestamps. Its simple… just call the | ||
function and pass the asset and an optional transform. | ||
|
||
Before: | ||
|
||
Template: {{ asset.url(transform) }} | ||
Output: http://example.com/uploads/images/_572x430_crop_center-center_80/James-Ellis_elevation-render-1.jpg | ||
|
||
After: | ||
|
||
Template: {{ nsm_rev_asset_url(asset, transform) }} | ||
Output: http://example.com/uploads/images/_572x430_crop_center-center_80/James-Ellis_elevation-render-1.1485302752.jpg | ||
|
||
## Installation | ||
|
||
### Step 1: Download the Bundle | ||
|
||
Open a command console, enter your project directory and execute the | ||
following command to download the latest stable version of this bundle: | ||
|
||
```console | ||
$ composer require newism/craft3-asset-rev | ||
``` | ||
|
||
This command requires you to have Composer installed globally, as explained | ||
in the [installation chapter](https://getcomposer.org/doc/00-intro.md) | ||
of the Composer documentation. | ||
|
||
### Step 2: Install | ||
|
||
Install plugin in the Craft Control Panel under Settings > Plugins. | ||
|
||
## Usage | ||
|
||
This plugin provides a single twig function: | ||
|
||
{{ nsm_rev_asset_url(asset, transform) }} | ||
|
||
### Server Configuration | ||
|
||
**Important**: This plugin doesn't actually change the the filename on the server. | ||
You'll need to implement rewrite rules in your apache conf or nginx access. | ||
|
||
#### Apache | ||
|
||
See: https://github.com/h5bp/server-configs-apache/blob/master/dist/.htaccess#L968-L984 | ||
|
||
# ---------------------------------------------------------------------- | ||
# | Filename-based cache busting | | ||
# ---------------------------------------------------------------------- | ||
|
||
# If you're not using a build process to manage your filename version | ||
# revving, you might want to consider enabling the following directives | ||
# to route all requests such as `/style.12345.css` to `/style.css`. | ||
# | ||
# To understand why this is important and even a better solution than | ||
# using something like `*.css?v231`, please see: | ||
# http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ | ||
|
||
# <IfModule mod_rewrite.c> | ||
# RewriteEngine On | ||
# RewriteCond %{REQUEST_FILENAME} !-f | ||
# RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1.$3 [L] | ||
# </IfModule> | ||
|
||
#### NGINX | ||
|
||
See: https://github.com/h5bp/server-configs-nginx/blob/master/h5bp/location/cache-busting.conf#L1-L10 | ||
|
||
# Built-in filename-based cache busting | ||
|
||
# This will route all requests for /css/style.20120716.css to /css/style.css | ||
# Read also this: github.com/h5bp/html5-boilerplate/wiki/cachebusting | ||
# This is not included by default, because it'd be better if you use the build | ||
# script to manage the file names. | ||
location ~* (.+)\.(?:\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ { | ||
try_files $uri $1.$2; | ||
} | ||
|
||
## Road Map | ||
|
||
Some things to do, and ideas for potential features: | ||
|
||
### 1.0 | ||
|
||
* Release it | ||
|
||
### Future | ||
|
||
* Add manfiest based revving | ||
* Integrate other 3rd party image manipulation plugins as they become available | ||
|
||
## Credits | ||
|
||
Brought to you by [Newism](http://newism.com.au) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "newism/craft3-asset-rev", | ||
"description": "Rev asset urls with timestamps", | ||
"type": "craft-plugin", | ||
"version": "0.0.1", | ||
"keywords": [ | ||
"craft", | ||
"cms", | ||
"craftcms", | ||
"craft-plugin", | ||
"nsm-asset-rev" | ||
], | ||
"support": { | ||
"docs": "https://github.com/newism/craft3-asset-rev/blob/master/README.md", | ||
"issues": "https://github.com/newism/craft3-asset-rev/issues" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Newism", | ||
"homepage": "http://newism.com.au" | ||
} | ||
], | ||
"require": { | ||
"craftcms/cms": "~3.0.0-beta.1" | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "composer", | ||
"url": "https://asset-packagist.org" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"newism\\assetrev\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"name": "NSM Asset Rev", | ||
"handle": "nsmAssetRev", | ||
"schemaVersion": "0.0.1", | ||
"hasCpSettings": false, | ||
"hasCpSection": false, | ||
"changelogUrl": "https://raw.githubusercontent.com/newism/craft3-asset-rev/master/CHANGELOG.md", | ||
"class": "newism\\assetrev\\NsmAssetRev" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
/** | ||
* NSM Asset Rev plugin for Craft CMS 3.x | ||
* | ||
* Rev asset urls with timestamps | ||
* | ||
* @link http://newism.com.au | ||
* @copyright Copyright (c) 2017 Newism | ||
*/ | ||
|
||
namespace newism\assetrev; | ||
|
||
use newism\assetrev\twigextensions\NsmAssetRevTwigExtension; | ||
|
||
use Craft; | ||
use craft\base\Plugin; | ||
use craft\services\Plugins; | ||
use craft\events\PluginEvent; | ||
|
||
use yii\base\Event; | ||
|
||
/** | ||
* Craft plugins are very much like little applications in and of themselves. We’ve made | ||
* it as simple as we can, but the training wheels are off. A little prior knowledge is | ||
* going to be required to write a plugin. | ||
* | ||
* For the purposes of the plugin docs, we’re going to assume that you know PHP and SQL, | ||
* as well as some semi-advanced concepts like object-oriented programming and PHP namespaces. | ||
* | ||
* https://craftcms.com/docs/plugins/introduction | ||
* | ||
* @author Newism | ||
* @package NsmAssetRev | ||
* @since 0.0.1 | ||
* | ||
*/ | ||
class NsmAssetRev extends Plugin | ||
{ | ||
// Static Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* Static property that is an instance of this plugin class so that it can be accessed via | ||
* NsmAssetRev::$plugin | ||
* | ||
* @var NsmAssetRev | ||
*/ | ||
public static $plugin; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* Set our $plugin static property to this class so that it can be accessed via | ||
* NsmAssetRev::$plugin | ||
* | ||
* Called after the plugin class is instantiated; do any one-time initialization | ||
* here such as hooks and events. | ||
* | ||
* If you have a '/vendor/autoload.php' file, it will be loaded for you automatically; | ||
* you do not need to load it in your init() method. | ||
* | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
self::$plugin = $this; | ||
|
||
// Add in our Twig extensions | ||
Craft::$app->view->twig->addExtension(new NsmAssetRevTwigExtension()); | ||
|
||
// Do something after we're installed | ||
Event::on( | ||
Plugins::className(), | ||
Plugins::EVENT_AFTER_INSTALL_PLUGIN, | ||
function (PluginEvent $event) { | ||
if ($event->plugin === $this) { | ||
// We were just installed | ||
} | ||
} | ||
); | ||
|
||
/** | ||
* Logging in Craft involves using one of the following methods: | ||
* | ||
* Craft::trace(): record a message to trace how a piece of code runs. This is mainly for development use. | ||
* Craft::info(): record a message that conveys some useful information. | ||
* Craft::warning(): record a warning message that indicates something unexpected has happened. | ||
* Craft::error(): record a fatal error that should be investigated as soon as possible. | ||
* | ||
* Unless `devMode` is on, only Craft::warning() & Craft::error() will log to `craft/storage/logs/web.log` | ||
* | ||
* It's recommended that you pass in the magic constant `__METHOD__` as the second parameter, which sets | ||
* the category to the method (prefixed with the fully qualified class name) where the constant appears. | ||
* | ||
* To enable the Yii debug toolbar, go to your user account in the AdminCP and check the | ||
* [] Show the debug toolbar on the front end & [] Show the debug toolbar on the Control Panel | ||
* | ||
* http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html | ||
*/ | ||
Craft::info( | ||
Craft::t( | ||
'nsmassetrev', | ||
'{name} plugin loaded', | ||
['name' => $this->name] | ||
), | ||
__METHOD__ | ||
); | ||
} | ||
|
||
// Protected Methods | ||
// ========================================================================= | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.