Special page links - Archived page


#1

I’m going through a mass site clean-up which requires archiving many assets.

It made sense to utilise the ‘Archived page’ option on my site’s Special page links. My goal was to print some specific messaging on all archived assets, but I’ve since learnt that:

a: The Archived page removes access to the archived page’s metadata (As I understand), so I am unable to print the desired message.

b: Despite the Squiz manual stating that the Archived asset “will be displayed if a user tries to view an archived asset for which they do not have read permission”.

As all our document assets are set to “Allow unrestricted access” I’m guessing the Archived page will never be fired in my scenario as I’m essentially breaking the links when archiving (losing __data).

Are there any ways around a: & b:? Any help or wisdom greatly appreciated.

For now I am considering paint layouts on the pages I am retiring to achieve what I need, but from a site admin perspective it feels wrong keeping their status’s to live. As for the docs, vanilla 404s

Matrix Version:6:33.0


(Mel Freeman) #2

I’m interested in what response you get here.

I’ve found this very frustrating for file assets. The URL changes when they are archived, and so the visitor gets Page Not Found when a document is archived. It’s a pity that this doesn’t work the way you intuitively expect.


(Harinder Singh) #3

I am sure you will be able to achieve it via triggers and session variables.

Also, you can place a customised message in your Page not found as follow:

%begin_globals_server_request_uri^contains:/__data/:1%
<p>Custom message for Data URLS</p>
%else_globals%
<p>Standard Content</p>
%end_globals%

#4

Awesome! Thank you @harinder.singh using a customised message for __data links was sufficient to achieve what I needed in this instance.

While on this topic, what keywords or methods are available to extract an archived asset’s metadata values when hit with a ‘Page not found’ or ‘Archived page’ asset?

Couldn’t agree more @MelFreeman, quite misleading and non-intuitive.


(Mel Freeman) #5

Not all __data 404s are archived though. Sometimes a new version of a file is uploaded and the file name changes. So I’m not sure how helpful your suggestion is, Harinder.

I think it would be much better if files that are archived showed the archive page, which is what is intuitive. Anyone on the product team noticing?


(Harinder Singh) #6

It was just to display a standard message for data URLs with a 404 error.

I was able to achieve the expected behavior with the help of JS and Triggers. The solution is not fully complete yet. I will post it when it is fully ready. So far, the testing is going well and is showing me the metadata value from archived file type assets as a public user.

It would be nice to see a more stable solution from the Squiz end.


(Harinder Singh) #7

I manage to achieve it by following:

  1. Content API Token

  1. Rest Resource Asset

URL: /__api/assets/%globals_get_param%?data=metadata,urls

Javascript in Rest Resource asset

let jsonData = _REST.response.body;
let response = JSON.parse(jsonData);

let filtered = [];
try {
    // Check if response is an object
    if (response && typeof response === 'object') {
        // Map the required properties to a new object
        filtered = {
            Id: response.id,
            Name: response.name,
            Status: response.status.code,
            description: response.metadata.description
        };
    }
   let assetUrl = '%globals_asset_url:' + filtered.Id +'%';

        print(`<p><strong>Status</strong> : ${filtered.Status}</p>`);
        print(`<p><strong>Asset ID</strong> : ${filtered.Id}</p>`);    
        if(filtered.description) print(`<p>${filtered.description}</p>`);    
        if(filtered.Status === "live") print(`<p>${assetUrl}</p>`);
        
} catch(e) { 
    print('Error: ' + e); 
}

Page Not Found (Bodycopy)

%begin_globals_server_request_uri^contains:/__data/:1%
    <h2>Document Not Found</h2>
    <div class="output"></div>    
    
    
    <script>
    function extractNumberFromUrl(url) {
        // Define the pattern to search for in the URL
        const pattern = /\/__data\/assets\/[^\/]+\/\d+\/(\d+)\//;

        // Execute the pattern on the URL
        const match = url.match(pattern);
        
        // If a match is found, return the extracted number, else return null
        return match ? match[1] : null;
    }
        
    $(document).ready(function() {             
        const url = "%globals_server_request_uri%";
        const extractedNumber = extractNumberFromUrl(url);
        
    // 11111 is your rest resource asset
    if(extractedNumber) {
        let requestUrl = "%globals_asset_url:11111%" + "?param=" + extractedNumber;

        $.ajax({
            url: requestUrl,
            type: 'GET',
            dataType: 'html',
            success: function(data) {
                $('.output').html(data)
            },
            error: function(xhr, status, error) {
                console.error('Error fetching metadata:', error);
            }
        });
    }
});
</script>
%else_globals%
    <h2>Page Not Found</h2>
%end_globals%

(Harinder Singh) #8

With above solution, we can print asset information(data url) even if they are archived. In case of the asset(document) is live, we can print the live URL of the asset or do a logic to redirect to the Live URL.

Limitation:

URL: /__api/assets/%globals_get_param%?data=metadata,urls

  • Above entry in the rest resource asset is unable to retrieve metadata and urls together along with the rest of the response data. Looking for suggestion to rectify this.
  • Only the first value “metadata” is accepting by the rest resource asset. “urls” is getting ignored.

Sample Links

Live URL

Archived URL