Sunday, August 1, 2021

Reading OSGI Configurations on AEM Cluod

OSGI Configurations are easy way to configure parameters based on run mode. This blogs details on how to create OSGI Configuration with different property attributes and read them through the code.

In this example, I have narrated a way to define Adobe Launch Script for various sites in OSGI configuration and dynamically read the script value based on the content site requested and add to the page template.

A site name is derived from the AEM page url structure

ex: /content/sitea/us/en - Site name is sitea. The Adobe Launch script  in the OSGI configuration will be defined as 

sitea.launch.script = "<source to the launch script>"

Here are the easy steps to implement them through project:

create the config file Under ui.config, 

com.demo.core.services.OSGiConfig.config.cfg.json with following values

{

"sitea.launch.script":"</assets.adobe.com/......xxxxx..min.js",
"siteb.launch.script":"</assets.adobe.com/......xxxxx..min.js"

}


demo.launch.script value will map to environment specific path for each run mode.

Create a new java class OSGiConfig.java with below code




In you page component model, write code to retreive the site name based on the url.

Create the property key as launchkey = siteName + "launch.script".

Create a getter method for getLaunchScript as follows

public String getLaunchScript()
{
return osgiConfig.getPropertyValue(launchKey);
}


In page component, customheaderlibs.html at the entry for including the scripttag

<script src="${pageModel.getLaunchScript}" async></script>


Saturday, July 31, 2021

Publishing Robots.txt in AEM Cloud

A robots.txt file informational document read by search crawlers that provides what URLs can be crawled on the site.

Robots.txt file is usually hosted at the root level of the site. For ex: https://www.abc.com/robots.txt.

Lets see how we ca implement this in AEM the easiest way: using dispatcher.

First create a robots.txt. Below is sample content of robots.txt file, which tells crawler the url for the sitemap. Sitemap is file hosted in your site, that tells crawlers, the important pages in your site. Sitemap is in XML format with urls to different pages in your site. You can call it as a simple bookmark for all your site structures. Sitemap.xml can be auto-generated (we will look into implementing sitemap.xml in another blog) or can be manually created. 

#Any search crawler can crawl our site
User-agent: *

#Allow only below mentioned paths
Allow: /en/

#Disallow everything else
Disallow: /

#Crawl all sitemaps mentioned below
Sitemap: https://[sitename]/sitemap.xml


Before we look into steps to implement the robots.txt, lets understand how the data flow occurs.
  • Robots.txt is hosted in AEM Dam. This allows authors to update the file without having to depend on the developers.
  • Crawler request (http://<site>/robots.txt) is routed through dispatcher
  • Dispatcher rewrites the request to publisher dam location /content/dam/<site>/robots.txt
  • Publisher responds back with robots.txt



Dispatcher applies the rewrite rules and redirects the 

Activities in AEM:
Login to AEM author environment and upload the file in the DAM. Path I am using is /content/dam/<site>/robots.txt. You can have separate robots.txt for each site managed in AEM. Publish the file so it gets replicated to the publisher.

Dispatcher Changes:
There are two places we need to modify in dispatcher.

Rewrite Rules:/conf.d/rewrites
In the rewrite rules,modify to redirect request for /robots.txt to publisher dam path.
RewriteRule ^/robots.txt$ /content/dam/<site>/robots.txt [PT,L]

Also set content disposition to inline - this allows robots.txt to be viewed in browser. Else robots.txt will download as file which will fail with crawlers

<LocationMatch "^(.*)/content\/dam*">
       Header unset "Content-Disposition"
        Header set Content-Disposition inline
</LocationMatch>

Filters:/conf.dispatcher.d/filters
In the filters for the site, modify to allow .txt extension for the path
/1001 { /type "allow" /extension '(txt)' /path "/content/*"}


Deploy the dispatcher configurations to cloud.

Now all requests to https://<site>/robots.txt should render the contents from robots.txt published though the DAM.




Sitemap.xml in AEM Cloud

An XML sitemap is a file that lists a website’s important pages, making sure Google and other search engines can find and crawl them all. It also helps search engines understand your website structure. Though search engines crawls all pages and links in the page, seldom sites end up with few pages that are not linked from any other pages (like the promo landing pages). Having those pages entered in sitemap.xml, speeds up the content discovery and get indexed.

This blog narrates the implementation of sitemap.xml using ACS AEM Commons  package. ACS AEM Commons package is open source package, originally built and supported by Adobe Consulting Services, later turned into an open source/AEM community maintained package. 

You can get more details on this and other features provided by package here 

Lets walk through the steps in implementing the sitemap.xml using this package.

  1. Create a OSGI Configuration for sitemap servlet.
    • create a file com.adobe.acs.commons.wcm.impl.SiteMapServlet-custom.cfg.json under ui.config/config. This setting will be common for all run modes.
    • Edit file with necessary parameters
    • sling.servlet.resourceTypes - This should have path to the page component in your project
    • externalizer.doain - this should have the domain name or the site name

  2. Create a OSGI Configuration for Externalizer Implementation
    • create a file com.day.cq.commons.impl.ExternalizerImpl.cfg.json.
    • This file should be created for each run mode (dev, qa, stage, prod) as the value will change for each environment
    • Entries have various site/domains and its relative URL - local, author and publish are updated by default by AEM.
    • add the new site and its url

Build and Deploy the changes to AEM instance. Now request to any page with .sitemap.xml should render the sitemap for the page.

Additionally, you can make dispatcher rewrite rule for /sitemap.xml to redirect to site home page with extention ".sitemap.xml" - ex: /content/<site>/us/en.sitemap.xml where en is the root home page for the site. This will generate sitemap with links to all pages in the site starting from root page and drill down to all child level pages.

Monday, February 4, 2013

Deploying a new master page

In this section, we can see how to deploy a master page to a site to provide consistent Look and feel across the pages. The master page provides the chrome contents that does not change from one site to another. Any given site may have following components across all pages
  • Header
    • Logo, Title, Search, 
  • Left navigation
  • Footer
To illustrate how to deploy a master page, I have used http://www.cancer.org site as a template. 


In the above screenshot, contents in yellow are page level contents that change from one page to another. Contents above the yellow box are Header and contents below the yellow box are footer. Here are the steps to create a master page template and publish to a 2013 Sharepoint site. 

First, extract the raw HTML and assets for the template. Assets can be Images, CSS files, JS files and any HTML files and store in a file structure :



Create a sharepoint site collection using "PublishingSite" template and login to the site, In this tutorial, I have created a publishing site in my office 365. The default OOB publishing site looks like this



Go to Settings --> Design Manager and select option 4 from left side items (4. Edit Master Pages). You should see list of available master page templates. Click on the top link that says "Convert an HTML to a SharePoint master page". You should see a pop-up that looks like a folder structure - header says "Select an Asset". Top link provides you the path you can use to create a "mapped network drive" from your windows desktop to easily manage the files. You can also upload files using browser by going to Site Settings --> Master pages and Page Layouts.

Once you copy the files (HTML, Images, JS and CSS files), you should see the file structure in the "Select an Asset" popup. Select the HTML file
and click "Insert" to add the HTML file to master page template collection.

 Once you selected, the Designer manager should list the file and status. If the status shows any warnings or errors, click on it to see details, fix the errors.


When the status says "conversion successfull", publish the master page - Click on the "..." and click on the "..." on the popup to open the sub menu and click "Publish a Major version"

All assets (images/styles/jscripts) should also be published. Unfortunately with this approach each file has to published one by one. To get to the files,
Click on "Convert an HTML file to a sharepoint master page" link on the top. Get the url from top that says "Current Location: Master Page Gallery at" and paste it on the address bar. Navigate to the folders that hosts all assets. Select the file and under "Ribbon control", select Files --> Publish. Repeat for all files



Once masterpage is published, Site master page should be associated with the new master page template.
Go to Site Settings and select "Master Page" under "Look and Feel".  Select the new master page from dropdown for "Site Master Page".  If you want the new UI to be applied to admin pages as well. select the template for "System Master Page" as well. Click OK and logoff and login to the site. Site should have the new look :

Tuesday, December 11, 2012

Setting up Developer Environment

Install following to setup an development environment for SharePoint 2013 Apps

1. Sharepoint Server 2013 - single server built-in database
2. Install Visual Studio 2012 Professional / Enterprise edition
3. Install Microsoft Office Developer Tools for Visual Studio 2012 from http://msdn.microsoft.com/en-us/office/apps/fp123627

Sharepoint 2013 Configuration Issue

When installing Sharepoint 2013 on a single server with Built-in database configuration, you may run in to issue when running the configuration wizard. I ran into the following issue at step 8:



After googling a while for a resolution, I found the following steps to resolve the issue
  1. Open windows explorer
  2. Go to C:\Program Files\Microsoft Office Servers\15.0\Data\Office Server" and find the directory that starts with Analytics. It should be "Analytics_<GUID>"
  3. Right-click, properties, Sharing and click Advanced Sharing
  4. Check the "Share this folder' checkbox, leave the Share name alone and click on Permissions
  5. Leave Everyone having Read (for now), Add the "Network Service" account and select Full Control. Do the same and add WSS_ADMIN_WPG with Full Control. Click OK and close properties dialog
  6. Run the SharePoint Configuration Wizard again. It should move on to step 9 and 10 and finish.


Single Server Built-in Database Installation

Finally, I was able to install a Sharepoint 2013 framework. I have documented the steps and errors I had received and steps to resolve those issues.

Environment:
Created a VM instance using VM Player 5.0.1 build-894247 with following hardware configuration
RAM : 3.5 GB
Maximum harddisk size : 80GB (stored in multiple files)
OS Type : Windows 2008

Installed following components in sequence
  1. Windows 2008 R2
  2. Install Service Pack 1 (KB976932)
  3. Install Sharepoint Software Prerequisites
    1. Launch sharepoint installer
    2. Select "Install software prerequisites"

    3. Review the list of components to be installed and click "Next"
    4. Accept the license agreement and click Next
    5. Review components intallation status and click finish.

  4. Install HotFixes/updates
    1. KB-2554876
    2. KB-2708075
    3. KB-2759112
  5. Install Sharepoint 2013
    1. Launch installer
    2. Select "Install Sharepoint Server"
    3. Enter product key
    4. Accept the terms of agreement

    5. Select Stand-alone option
    6. Complete the installation
    7. Close installation program
6.    Launch Configuration wizard
  1. Start --> Program files -> Microsoft Sharepoint 2013 Products --> Sharepoint 2013 Products Configuration Wizard
  2. Click Next on Welcome screen
  3. Click YES when prompted to stop services
  4. Complete the configuration wizard.

Installation of Sharepoint should be complete.  You can launch the Sharepoint Central Administration from Start programs to confirm successfull installation of Sharepoint.