I'm making a photo gallery/lightbox and am using graphql to manage the pictures.
I have 10 photos in a folder: "1- Picture.png", "2- Picture of other thing.png", "3-...", ..., "10- My last picture.png"
I'm using the following snippet to sort in ascending order,
export const query = graphql`
query($gallery: String!) {
allFile(
filter: {
sourceInstanceName: { eq: "galleries" }
absolutePath: { glob: $gallery }
}
sort: { fields: name, order: ASC }
) {
nodes {
name
childImageSharp {
fluid(maxWidth:1920, quality:90) {
...GatsbyImageSharpFluid
}
}
}
}
}
`
But the output order is "1- Picture.png", "10- My last picture.png", "2- Picture of other thing.png",...
Is there an intelligent way to sort by the number at the start of the string? The easiest way I can think of is to rename the 1-9 files "01-...png", but I'm trying to implement this for several thousand folders of 5-150 photos, all with this "1-" naming convention.
How do I sort these photos such that "9- Some name.png" is listed before "10- My last picture.png"?