Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last updated date to template context #38

Open
adamghill opened this issue Sep 29, 2022 · 2 comments
Open

Add last updated date to template context #38

adamghill opened this issue Sep 29, 2022 · 2 comments

Comments

@adamghill
Copy link
Owner

Either last_updated_date or modified_date.

Some more thoughts #29 (comment) and #29 (comment).

@Tobi-De
Copy link
Contributor

Tobi-De commented Sep 30, 2022

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"

@adamghill
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants