Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts

Thursday, May 16, 2019

Adobe Experience Manager (AEM) Link Transformer

I've been taught the wrong way to configure the Adobe Experience Manager (AEM) /etc/mappings in the past. There's zero documentation about how your URL, rendered from the Path Browser widget, gets Transformed to a relative URL hiding /content/sitename. Everyone says that the node name is important (it's not). So after spending an hour trying to sort this out, here's how it works.

You can create your own Link Rewriter by implementing the org.apache.sling.rewriter.Transformer interface. Adobe comes with one out-of-the-box that will use the Sling Mappings for Resource Resolution (a.k.a. /etc/mappings). The key is setting up your /etc/mapping correctly.

Here's an example of an /etc/mapping for a SSL (https) Site:


The OOTB Link Transformer will traverse your configured /etc/map directory from top to bottom, based on the node order. This is why setting the "jcr:primaryType" to "sling:OrderedFolder" is so important.

As it traverses the nodes, the first sling:internalRedirect regex that matches the link path will be used to rewrite the URL to what is set in the sling:match property. It uses the following values to rewrite the link:

  • Protocol is selected based on the parent http or https;
  • The regex grouping(s) that are created from the sling:internalRedirect property are used when rewriting the link; and
  • The link will be rewritten using a combination of the protocol and the sling:match regex.


This is why using a sling:OrderedFolder is so important. As all sites should be https; if we have multiple sites and domains, and we offer linking via AEM Path Browser between them, we need to configure the sites to create fully qualified URLs with https. Without an Ordered Folder, http configurations would be ordered above https and this wouldn't work. Same with doing multiple mappings within a protocol node.

Finally, whatever domain is configured to at the Dispatcher will be used as part of Link Transformer to match and write a relative path. So...

  • If your domain is bmxcode.com and that points to your reverse proxy;
  • Your domain bmxcode.blogspot.com points at your AEM instance; then
  • Set your "sling:match: property to "bmxcode.blogspot.com/$1" and this will rewrite your links as relative URLs (without the protocol and domain).


Hope this helps!

Friday, October 28, 2016

Using Maven to create an RPM distribution

I've been digging around trying to find the minimum POM configuration to create an RPM distribution using Maven. Here it is for anyone else who needs it.

Tuesday, May 31, 2016

Cheeky Git Commands

Just storing the list of git commands I seem to always come back to trying to find. Will reference the original source when possible.

Update the remote branch list on your local (Detlus Knowldge)
$ git remote update origin --prune

Replace the local version with the remote version
$ # fetch the latest changes
$ git fetch origin
$
$ # reset the branch to fetched changes (assuming you're working on master)
$ git reset --hard origin/master

Rename a local branch (pre-push to origin)
$ # checkout the branch to rename
$ git checkout branch-name
$ 
$ # rename the branch
$ git branch -m new-branch-name

Push and track a local branch to origin
$ # switch the branch to push and track
$ git checkout branch-name
$ 
$ # push the branch to origin
$ git push -u origin branch-name

Thursday, September 17, 2015

OOTB Forms VS AEM Forms

Adobe Experience Manager has two Forms products:
  • Default (Out Of The Box) Forms - The very basic form components to build simple forms within a page; and
  • Experience Manager Forms - Previously known as AEM Forms this is the full-blown, Lifecycle integrated Adaptive Forms suite. It's also an additional license cost!
The way the Adobe Doc's site has been reformatted makes it difficult to find any information. I'm posting this blog as an easy way for me to reference the documentation for each.

Default OOTB Forms
Experience Manager Forms (The Paid Version)

Sunday, September 13, 2015

Adding Justified Gallery to your Blogger Template

I've just come back from BMXPO 2015 and have taken about 70 pictures of some amazing BMX bikes and now it's time to get them up onto my blog. I've been looking into how I could add a image thumbnail gallery to a blogger post and I didn't come up with anything relevant and up-to-date, so I'm writing my own.

I've chosen Justified Gallery created by Miro Mannino. It's a clean, simple, open source jQuery plugin that creates an image gallery and incorporates Colorbox lightbox. I'm also using cdnjs as my JavaScript and CSS CDN provider, primarily because they had the latest version of Justified Gallery, jQuery and Colorbox libraries.

Update your Blogger Template to include the CSS and JavaScript libraries. Login to your Blogger Dashboard, then go to Template > Edit HTML. Place the cursor into the editor and use the keyboard shortcut for Find... and search for </head>. All JavaScript and CSS libraries will be placed above the head close tag.

Add the following CSS and JavaScript libraries:
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js">
<link href='//cdnjs.cloudflare.com/ajax/libs/justifiedGallery/3.6.0/css/justifiedGallery.min.css' rel='stylesheet'/>
<script src='//cdnjs.cloudflare.com/ajax/libs/justifiedGallery/3.6.0/js/jquery.justifiedGallery.min.js'/>

Optionally, add the following CSS and JavaScript libraries if you want to use Colorbox lightbox instead of the default blogger lightbox. The 'cbconf' provides an easy reference to hold the Colorbox configuration so that it does not have to be written each time we create a gallery.
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery.colorbox/1.4.33/jquery.colorbox-min.js'/>
<link href='//cdnjs.cloudflare.com/ajax/libs/jquery.colorbox/1.4.33/example1/colorbox.css' rel='stylesheet'/>
<script type='text/javascript'>
   cbconf = {
      maxWidth : '80%',
      maxHeight : '80%',
      opacity : 0.8,
      transition : 'elastic',
      current : '';
   };
</script>

To insert a Justified Gallery into a blog post or blog page, switch to the HTML view and add in the following HTML snippet:
<div id="picGallery">
    <!-- insert images here -->

</div>
<script>
    $('#picGallery').justifiedGallery({
        lastRow: 'justify',
        captions: false,
        rel: 'uniqueName'
    });
</script>

Update the div and jQuery ID's to be unique name for the post. This is to prevent multiple firing of the same Justified Gallery scripts on the blog roll.

The JS configuration within the Justified Gallery script tag specifies:
  • lastRow: 'justify' ensure that the last row images are enlarged to fit the entire row;
  • captions: false disables displaying of captions; and
  • rel: 'uniqueName' provides Justified Gallery with a relationship name to group the images within the same lightbox. Update uniqueName to the same value that was set for picGallery.
Additional Justified Gallery options can be added depending on the requirements.

The next step is to add your images. Stay in the HTML view, place the cursor below the comment and click on the "Insert Image" icon; upload and/or select the images to be added to the blog post; click the Add button and select Image Alignment: None and Image Size: Small. Small is the perfect size for thumbnail images. The HTML view image inserts are added in the correct format for Justified Gallery.

Modify the last two thumbnail images to be 600px in size to ensure that the correct sized images are displayed on the justified last row. The Blogger image paths are REST-ful URI's and the final element determines the image size. Change the "/s200/" to "/s600/" for the last two image elements.

Here is a working sample of the BMX's that I took to BMXPO 2015:


Finally, if you would like to use Colorbox as your lightbox, you will need to modify the Justified Gallery script with the below options.
<script>
    $('#picGallery').justifiedGallery({
        lastRow: 'justify',
        captions: false,
        rel: 'uniqueName'
    }).on('jg.complete', function() {
        $(this).find('a').colorbox(cbconf);
    });
</script>

The above snippet calls the Colorbox function on all links within the picGallery div and applies the referenced configuration. If you have not disabled the default blogger lightbox, both lightboxes will appear at the same time.

To disable the default blogger lightbox login to your Blogger Dashboard; then go to Settings > Post Comments; and set "Showcase images with Lightbox" to "NO".