coltrane icon indicating copy to clipboard operation
coltrane copied to clipboard

Add last updated date to template context

Open adamghill opened this issue 3 years ago • 2 comments

Either last_updated_date or modified_date.

Some more thoughts https://github.com/adamghill/coltrane/issues/29#issuecomment-1260813736 and https://github.com/adamghill/coltrane/issues/29#issuecomment-1261069008.

adamghill avatar Sep 29 '22 15:09 adamghill

I want to make sure I understand how the manifest file is being used at the moment.

The manfiest file output.json is generated and updated (if the content has changed) every time coltrane build is run. At the moment, the manifest is only used to check if things have changed when the build command is executed and nowhere else in the codebase.

Currently, the manfiest file is generated in the base directory and not in the output directory where the static site is generated. I'm not sure why, perhaps because the output directory could easily be changed and should be considered disposable, but the manifest file should persist between builds?

If we decide to use the manifest file to provide a last_updated_date in the context, for standone and static there will probably be no issues since the manifest file is available in both cases but for integrated mode there is currently no way to have one. The first idea that comes to my mind is a simple management command that generates a manifest file, this could work for any mode but users of standalone and static won't really need it. This command will do something like this:


def handle(self, *args, **kwargs):
	manifest =  Manifest(manifest_file=get_output_json())
	is_force = "force" in options and options["force"] is True
	is_skipped = False
	
	for path in get_content_paths():
		 item = ManifestItem.create(markdown_file)
         existing_item = self.manifest.get(markdown_file)
		 
		  if existing_item and not is_force:
            if item.mtime == existing_item.mtime:
                is_skipped = True
            elif item.md5 == existing_item.md5:
                # Update item in manifest to get newest mtime
                self.manifest.add(markdown_file)

                is_skipped = True

        if not is_skipped:
           self.manifest.add(markdown_file)


	if manifest.is_dirty:
		manifest.write_data()

This is a basic example of how it might work, I've left out multithreading stuff for now. The code above is copied from the existing build command and I don't see right now an easy way to extract this code and make it reusable. The more I think about it, the less it seems like a good idea or something useful.

Also, in an integrated scenario, a file named output.json could lead to confusion I think, I'll suggest something like content_manfiest.json (I agree, it's really ugly) or content.json but if this change can lead to unnecessary complication in the project, especially for existing users, we can leave it as it is, it's not a big deal. We could also make the path configurable like this:

def get_output_json() -> Path:
    """
    Get the path of the JSON manifest `output.json` file.
    """

    try:
        return settings.COLTRANE["OUTPUT"]["MANIFEST"]
    except (AttributeError, KeyError):
        pass

    return get_base_directory() / "output.json"

Tobi-De avatar Sep 30 '22 10:09 Tobi-De

the manfiest file is generated in the base directory and not in the output directory

My thought was that output.json shouldn't be served with the static html from the output directory.

adamghill avatar Sep 30 '22 12:09 adamghill