def copy_file(self, dirty: bool = False) -> None:
        """Copy source file to destination, ensuring parent directories exist."""
        if dirty and not self.is_modified():
            log.debug(f"Skip copying unmodified file: '{self.src_uri}'")
            return
        log.debug(f"Copying media file: '{self.src_uri}'")
        output_path = self.abs_dest_path
        os.makedirs(os.path.dirname(output_path), exist_ok=True)
        content = self._content
        if content is None:
            assert self.abs_src_path is not None
            try:
                utils.copy_file(self.abs_src_path, output_path)
            except shutil.SameFileError:
                pass  # Let plugins write directly into site_dir.
        elif isinstance(content, str):
            with open(output_path, 'w', encoding='utf-8') as output_file:
                output_file.write(content)
        else:
            with open(output_path, 'wb') as output_file:
                output_file.write(content)
Copy source file to destination, ensuring parent directories exist.
mkdocs/structure/files.py